gpt4 book ai didi

javascript - ExtJS MVC : should controllers be specified within requires for application?

转载 作者:行者123 更新时间:2023-11-29 16:16:31 24 4
gpt4 key购买 nike

如果 Ext.application 具有以下 Controller :

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

Ext.application({
name: 'MyApp',
appFolder: 'app',

controllers: [
'Ctrl1',
'Ctrl2'
],

launch: function() { ... }
});

是否还应该在 requires 部分的 controllers 中包含 Controller ,即添加

requires: [
'MyApp.controller.Ctrl1',
'MyApp.controller.Ctrl2'
],

在上面的类中?

最佳答案

简短的回答是否定的。

长答案是 controllersmodelsviewsstores 配置都转换为 要求。神奇之处在于 Ext.app.Controller类:

onClassExtended: function(cls, data, hooks) {
var Controller = Ext.app.Controller,
className, namespace, onBeforeClassCreated, requires, proto, match;

className = Ext.getClassName(cls);
namespace = Ext.Loader.getPrefix(className) ||
((match = className.match(/^(.*)\.controller\./)) && match[1]);

if (namespace && namespace !== className) {
onBeforeClassCreated = hooks.onBeforeCreated;
requires = [];

hooks.onBeforeCreated = function(cls, data) {
proto = cls.prototype;

Controller.processDependencies(proto, requires, namespace, 'model', data.models);
Controller.processDependencies(proto, requires, namespace, 'view', data.views);
Controller.processDependencies(proto, requires, namespace, 'store', data.stores);
Controller.processDependencies(proto, requires, namespace, 'controller', data.controllers);

// this is the line to look at!!!
Ext.require(requires, Ext.Function.pass(onBeforeClassCreated, arguments, this));
};
}
},

您的应用程序只是一个继承自 Ext.app.ControllerExt.app.Application 类;因此 controllers 配置也转换为 requires

关于javascript - ExtJS MVC : should controllers be specified within requires for application?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14758201/

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