Call controller's function from another controller / Share data between controllers

好久不见. 提交于 2019-11-29 04:01:45

I would use the getController method: http://docs.sencha.com/touch/2-0/#!/api/Ext.app.Application-method-getController

EG: this.getApplication().getController('ControllerName').doSomething();

If you're not in the context of your Controller(for example in a callback function of some object), you can do this.

MyAppName.app.getController('ControllerName').doSomething();

When using the MVC convention in Sencha Touch 2, I would recommend the following when trying to call a method called 'SomeMethodInB' in 'ControllerB' from inside 'ControllerA':

MyAppName.app.getController('ControllerB').

'MyAppName' is the name of the app you defined in the core app definition - typically in your app.js file.

According to the Sencha forums, the below is depreciated:

this.getApplication().getController('ControllerB').SomeMethodInB();

http://www.sencha.com/forum/showthread.php?158996

In fact the only way I can call the "this.getApplication()" method to even work is when calling it from my app definition file (app.js).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!