Pra*_*ane 5 extjs extjs4 extjs-mvc extjs4.1
我在extjs4工作.我陷入了想要在extjs4中动态加载控制器的点.我正在使用控制器this.getController()方法动态加载控制器.*当我将此代码放在特定控制器的init()函数中时,它会工作,控制器会动态加载.*这是我的控制器代码......
Ext.define('B.UserController',{
----
init:function()
{
var controller = this.getController('kp.PollController');
controller.init(); // launch init() method
this.control(
{
'KpLogin button[action=loginAction]':
{
click:this.authenticateUser
},
});
},
-----
Run Code Online (Sandbox Code Playgroud)
但是,当我将我的代码放在特定功能(按钮事件)时,它会给我错误.这是我的代码......
Ext.define('B.UserController',{
-------
init:function()
{
this.control(
{
'KpLogin button[action=loginAction]':
{
click:this.authenticateUser
},
});
},
authenticateUser:function(button)
{
var controller = this.getController('kp.PollController');
controller.init(); // launch init() method
}
-----
Run Code Online (Sandbox Code Playgroud)
放入此代码后,我在firebug中出错了...
Uncaught TypeError: Cannot read property 'readyState' of undefined Connection.js:818
Ext.define.onStateChange Connection.js:818
(anonymous function)
Run Code Online (Sandbox Code Playgroud)
这是我的app.js代码....
Ext.application({
name:'B',
autoCreateViewport:true,
controllers:['sn.UserController','qb.QbquestionController','kp.DnycontentController',/*'kp.PollController','kp.PolloptionController',*/'kp.KpquotationController','qb.QbqnsController','kp.CuriosityquestionController','kp.WordController','kp.DnycontentcategoriesController'],
launch:function()
{
console.log('Application launch');
},//End of launch function
});
Run Code Online (Sandbox Code Playgroud)
我不知道什么是错的.请给我一些建议....
您确定控制器尚未加载吗?因为当您处于控制器 X 的 init 函数中时,您无法确定控制器 Y 是否已加载,并且不会在调用init()该控制器时抛出错误。
我认为您需要检查您的控制器是否尚未加载:
if (!this.application.controllers.get(controllerName)) {
var controller = this.getController(controllerName);
controller.init();
}
Run Code Online (Sandbox Code Playgroud)
因为如果 init 已经执行,它将无法工作并抛出异常,就像您指出的那样。
你的控制器数组中有什么Ext.application()?