gpt4 book ai didi

function - 如何在 Sencha Architect 中创建函数?

转载 作者:行者123 更新时间:2023-12-03 21:37:08 25 4
gpt4 key购买 nike

Ext.Ajax.request({
url: 'foo.php', // where you wanna post
success: passFn, // function called on success
failure: failFn,
params: { foo: 'bar' } // your json data
});

我正在关注 How to post json data with extJS并得到了关于功能的问题。我看到我们可以在 passFn 和 failFn 区域中嵌入函数。但是,如果我希望这些功能位于其他地方怎么办?在 Sencha Architect 中在哪里创建这些函数并对其进行编码?

最佳答案

您可以创建一个不受 Sencha Architect 控制的文件夹,并从您的 Architect 代码中调用它。

例如,我喜欢创建一个名为“util”的文件夹。因此,您的文件夹结构如下所示:

app
-- controller
-- model
-- store
-- view
-- util <--- I added this directory
-- MiscFunctions.js <-- your own class file

在 MiscFunctions.js 中,您可以像这样创建类:

Ext.define('MyApp.util.MiscFunctions', {
singleton: true,
passFn: function() {
...
},
failFn: function() {
}
});

然后您可以在您的 Architect 代码中引用这些函数:

Ext.Ajax.request({
url: 'foo.php', // where you wanna post
success: MyApp.util.MiscFunctions.passFn, // function called on success
failure: MyApp.util.MiscFunctions.failFn,
params: { foo: 'bar' } // your json data
});

不要忘记添加

singleton: true

部分,否则您将必须创建该类的实例才能使用其中的函数。

关于function - 如何在 Sencha Architect 中创建函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10402386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com