我正在尝试将 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 ) };
所以我可能会实现一些机制,当我创建它们时,它会自动将应用程序添加到这些控制器中。