Sencha touch 2- Ext.dispatch replacement?

别说谁变了你拦得住时间么 提交于 2020-01-01 08:52:26

问题


What is the replacement for sencha touch 1.1 Ext.dispatch method in sencha touch 2?

I need replacement for code below

listeners:{
    itemtap:function(data,index){
        var record = data.getStore().getAt(index);
         // the record that has been clicked.
         Ext.dispatch({
            controller: 'ControllerName'
            ,action: 'ControllerMethod'
            ,record: record
        });
    }
}

回答1:


Method Ext.dispatch still exists in Sencha Touch 2: http://docs.sencha.com/touch/2-0/#!/api/Ext.app.Application-method-dispatch

But if you just don't like to use it for some reason, you can get an instance of the controller and call method dicrectly:

Ext.ControllerManager.get('ControllerName').ControllerMethod({record: record});



回答2:


In sencha touch 2.0 to get the controller instances from anywhere use

<your app name>.app.getController('your controller name');

where your application name is setup in app.js




回答3:


Try this, it should work:

window['AppName'].app.getController('ControllerName').MethodName(Args)

Or, alternatively:

window['AppName'].app.dispatch({
    controller: 'ControllerName',
    action: 'MethodName',
    args:ArgsArray
}



回答4:


When the call shal be done from a controller, you'll have the application instance by getApplication method, there is a method getControllerInstance which returns an array.

this.getApplication().getControllerInstances()['yourcontrollername'].yourmethod(yourparams)



回答5:


yourAppName.getApplication().getController('yourControllerId').yourMethodName(args);


来源:https://stackoverflow.com/questions/8033185/sencha-touch-2-ext-dispatch-replacement

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