无法从外部对象访问控制器
Cannot access controllers from outside object
我这里有一些简单的代码。它创建了一个名为 'MyApp' 的 application 并定义了一个名为 'MyController' 的 controller。然后 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()
但是 none 这些东西似乎有效...我也在使用 Extjs 4.1,这可能是个问题。基本上我想以某种方式从我的代码内部访问我的控制器(不一定来自另一个控制器)
这里是问题的 fiddle :
我没问题(一旦我移动了你的 controller/application)。
function onDeviceReady() {
MyApp.app.getController('MyController').somefunction();
}
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
init: function() {
onDeviceReady();
},
somefunction: function() {
alert('some function callled')
}
});
Ext.application({
name: 'MyApp',
controllers: ['MyController']
});
https://fiddle.sencha.com/#fiddle/1jk7
然而,这并不是我做事的方式。我宁愿没有全局函数,而是让它深入到我的应用程序中。我宁愿有一个单身人士 class 我会触发事件,这样控制器就会收听这些事件。还有,下车4.1 :)
我这里有一些简单的代码。它创建了一个名为 'MyApp' 的 application 并定义了一个名为 'MyController' 的 controller。然后 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()
但是 none 这些东西似乎有效...我也在使用 Extjs 4.1,这可能是个问题。基本上我想以某种方式从我的代码内部访问我的控制器(不一定来自另一个控制器)
这里是问题的 fiddle :
我没问题(一旦我移动了你的 controller/application)。
function onDeviceReady() {
MyApp.app.getController('MyController').somefunction();
}
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
init: function() {
onDeviceReady();
},
somefunction: function() {
alert('some function callled')
}
});
Ext.application({
name: 'MyApp',
controllers: ['MyController']
});
https://fiddle.sencha.com/#fiddle/1jk7
然而,这并不是我做事的方式。我宁愿没有全局函数,而是让它深入到我的应用程序中。我宁愿有一个单身人士 class 我会触发事件,这样控制器就会收听这些事件。还有,下车4.1 :)