【发布时间】:2012-04-17 15:36:15
【问题描述】:
我正在尝试将 ExtJS4 应用程序拆分为模块。
- app
- store
- controller
- model
- view
- module
- m1
- model
- view
- controller
- m2
- model
- ...
问题是,当我启动应用程序并初始化其中一个 m1 控制器时,该控制器没有 this.control() 函数。
-- 编辑--
我在控制器文件夹中定义了一个类。
Ext.define( 'App.module.ping.controller.Ping', {
extend: 'Ext.app.Controller',
requires: [
'App.module.ping.view.PingPanel'
],
init: function() {
this.control( {
'#app.module.ping': {
render: this.onPanelRendered
}
} );
},
onPanelRendered: function() {
...
}
});
稍后我会打电话
Ext.create('App.module.ping.controller.Ping').init();
但我收到此错误:
Uncaught TypeError: Cannot call method 'control' of undefined
Ext.define.control./lib/extjs-4.1.0/src/app/Controller.js:414
Ext.define.init./app/module/ping/app/controller/Ping.js:11
Ext.define.init./app/module/ping/app/Module.js:11
(anonymous function)app.js:17
(anonymous function)app.js:35
Module.js 是带有 create() 调用的文件 Ping.js 是带有 define() 调用的文件
-- 编辑2--
病理例子:
输入:
Ext.define( 'MyController', {
extend: 'Ext.app.Controller',
init: function() { console.log('initialized'); }
});
输出:
function constructor() {
return this.constructor.apply(this, arguments);
}
输入:
Ext.create('MyController');
输出:
constructor
输入:
MyController.create();
输出:
constructor
-- 编辑3--
控制器在创建时需要配置对象中的应用程序对象。应用程序对象将自己添加到所有控制器中,这些控制器不是使用 create 手动创建的。它调用这样的东西:
Ext.create('App.controller.Users', { application: this, ... } );
稍后它使用应用程序对象将控制调用重定向到它。
control: function ( config ) { this.application.control( config ) };
所以我可能会实现一些机制,在创建这些控制器时自动将应用程序添加到这些控制器中。
【问题讨论】:
-
控制器没有 control() 函数到底是什么意思?你能把你的一些代码贴在它发生的地方吗?
-
错误信息对我没有帮助。控制被调用,但它说这是未定义的...... wat?!
-
恭喜您找到了解决方案!也许它会让你重新使用他们喜欢的方法来组织源代码:) 我发现 ExtJs 在几个地方依赖于目录结构,因此决定不发明任何东西并按照他们的建议来组织东西。
-
但我想要 app/module1/controller 而不是 app/controller/module1... 他们的首选方法我也会得到 app/view/module1 app/model/module1 等。我只想要一个目录其中包含模块需要插入其他应用程序并独立运行的所有内容:\
标签: model-view-controller extjs extjs-mvc