For the moment, when I'm in a controller and that I want to call a function from another controller, I do this :
App.app.getControllerInstances()['App.controller.OtherController'].do_something();
Is seems a bit heavy to me, is there another (better) way to do this ?
Thanks
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).
来源:https://stackoverflow.com/questions/10669647/call-controllers-function-from-another-controller-share-data-between-controll