【发布时间】:2017-03-13 19:04:14
【问题描述】:
我这里有一些简单的代码。它创建了一个名为“MyApp”的应用程序,并定义了一个名为“MyController”的控制器。 MyController 然后作为配置传入应用程序。
function onDeviceReady() {
alert('In onDeviceReady() function');
MyApp.app.getController('MyController').somefunction();
// MyApp.controller.MyController.somefunction()
}
Ext.application({
name: 'MyApp',
controllers: ['MyController']
});
Ext.define( 'MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
init: function () {
alert('Login controller');
onDeviceReady();
},
somefunction:function(){
alert ( 'some function callled' )
}
});
到目前为止一切顺利。典型的标准东西。现在,在从 MyController 调用“init”之后,我调用了一些外部方法 onDevideReady。通过这种方法,我想再次访问我的控制器。
我已经尝试过:
- MyApp.app.getController('MyController').somefunction();
- MyApp.controller.MyController.somefunction()
但是这些东西似乎都不起作用......我也在使用 Extjs 4.1,这可能是一个问题。基本上我想以某种方式从我的代码中访问我的控制器(不一定来自另一个控制器)
这是问题的关键:
【问题讨论】: