gpt4 book ai didi

extjs - 在 app.js Extjs 中定义 Controller

转载 作者:行者123 更新时间:2023-12-04 18:13:03 25 4
gpt4 key购买 nike

这是我的 app.js 代码:

Ext.Loader.setConfig({
enabled: true
});

Ext.application({
name: 'KP',
appFolder: 'scripts/app',

controllers: [
'login.Login'
],

views: [
'login.Login'
],


launch: function () {

var view = Ext.widget('login')
}


});

如果我想在我的应用程序中使用其他一些 View 、 Controller 、模型和存储,我应该在 app.js 中定义它们吗? (像这样: Controller [....我所有的 Controller .....])
还有其他方法可以在我的 Controller 中使用 init 功能吗?谢谢!

最佳答案

有很多方法...

首先了解一些基础知识:

应用程序 Controller 的 Controller 数组中列出的所有 Controller 都在启动时被实例化(应用程序使用 onReady 事件进行初始化。同时调用列出的 Controller 的 init()onLaunch() 方法。有关详细信息,请参阅链接的 API发生这种情况)。现在每个实例化的 Controller 都初始化它的存储、 View 和模型(为所有创建 getter 并创建每个存储的实例同时覆盖 storeId 并将它们附加到 Ext.StoreMgr )。请注意,每个 Controller 都将包含他自己的模型、存储和 View 。

接收未在应用程序 Controller 中列出的 Controller 的最简单方法是使用应用程序 Controller 的引用并调用 getController(name)

重要的是要知道,当使用这种方式接收 Controller 实例时,getter 方法不会调用 init()。或 onLaunch()调用 Controller 的方法,它只会尝试获取或创建 Controller 。您还应该注意这些 Controller 中这些方法的 API 不再正确。您需要为这些 Controller 设置一个 init bool 并在 getController(name) 的引用上检查它。方法交还给你。如果它是 undefined/false,你调用 init()/onLaunch()自己设置,然后设置。我自己使用这些技术来减少更大应用程序的初始负载。我猜你并不真的需要这个仅仅为少数 Controller 。

Update

Due to some changes in the 4.1.x release it is no longer required to init the controller manually. This is now done for us by the getController method

关于extjs - 在 app.js Extjs 中定义 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12243194/

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