我正在尝试将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:35Module.js是带create()调用的文件,Ping.js是带有Ping.js()调用的文件
- edit2 --
病理例:
投入:
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- edit3 --
当创建配置对象时,控制器需要配置对象中的应用程序对象。应用程序对象将自身添加到所有控制器中,这些控制器不是用create手动创建的。它称之为这样的东西:
Ext.create('App.controller.Users', { application: this, ... } );稍后,它使用应用程序对象将控制调用重定向到它。
control: function ( config ) { this.application.control( config ) };所以我可能会实现一些机制,当我创建控制器时,它会自动地将应用程序添加到这些控制器中。
发布于 2012-04-18 21:45:19
你试过吗
var pingController = Application.getController('App.module.ping.controller.Ping');
pingController.init(); //or pingController.init(Application);其中,应用程序是对在Ext.application.launch期间创建的对象的引用,例如
var Application = {};
Ext.application({
//all of your settings,
launch:function(){
Application = this;
//other launch code
}
}
});发布于 2013-10-25 16:25:06
来此寻找解决方案的其他人:
Uncaught TypeError: Cannot call method 'control' of undefined除了一整天的沮丧之外,上面的答案并没有解决我的问题,而是引导我尝试了以下几点,从而解决了这个问题:
// app.js
Ext.application({
...
launch: function(){
var me = this;
...
me.getController('ControllerName');
}
});
// inside controller/ControllerName.js
init: function(app){
var me = this;
app.control({
'#editButton': {
click: function(){
me.someFunction();
}
}
});
},这个app变量与为问题选择的答案中的"var Application = {}“相同--这意味着我不需要在全局(或者根本不需要)添加它。我一定尝试过无数种不同的东西,但最终还是成功了。希望它能救别人。
发布于 2012-04-18 10:19:08
不需要手动调用init()。只需调用Ext.create,构造函数就会自动调用。
https://stackoverflow.com/questions/10194316
复制相似问题