在Sencha Architect中,如何调用自定义函数?

时间:2014-11-05 07:50:14

标签: extjs

我在Sencha Architect中创建了一个控制器,然后创建了一个函数,但是当我运行该程序时,它说“TypeError:this.epoSetValues不是函数”。我怎么称呼这个功能?

Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',

config: {
    refs: {
        epoTabPanel: '#epoTabPanel'
    },

    control: {
        "#epoTabPanel": {
            initialize: 'onEpoTabPanelInitialize'
        }
    }
},

onEpoTabPanelInitialize: function(component, eOpts) {
    Ext.data.JsonP.request({
                 url: 'http://192.45.1.178/str/20141027085543295a746e70bab8f1c08cbec9462f2a02256',
                 timeout: 30000,
                 callbackKey: '',
                 callback: function() { 
                 },
                 success: function(result) { 
                    this.epoSetValues(result.po_id);
                 },
                 failure: function() {
                 }
             });

},

epoSetValues: function(po_id) {
            Ext.getCmp('po_id').setTitle(po_id);
}

});

1 个答案:

答案 0 :(得分:0)

原因是this范围在Ext.data.JsonP.request内不同。它的范围是Ext.data.JsonP。这样做:

var me=this;
Ext.data.JsonP.request({
             url: 'http://192.45.1.178/str/20141027085543295a746e70bab8f1c08cbec9462f2a02256',
             timeout: 30000,
             callbackKey: '',
             callback: function() { 
             },
             success: function(result) { 
                me.epoSetValues(result.po_id);
             },
             failure: function() {
             }
         });