0

当 ajax 调用成功时,我需要更新 sencha 模板。示例代码如下

Ext.define('casta.view.Intro', {
    extend: 'Ext.tab.Panel',
    tpl: '<p> {username} </p>',
    initComponent: function(){
        //Be sure to use the var keyword for planet earth, otherwise its declared as a global variable
        //var planetEarth = { name: "Earth", mass: 1.00 };
       //this.setHtml(this.getTpl().apply(planetEarth));
         Ext.Ajax.request( 
        {    
            waitMsg: 'Bitte warten...', 
            url: 'http://localhost:8000/api/casta/user/?format=json', 

            success:function(response,options){ 
                //var responseData = Ext.util.JSON.decode(response.responseText); 
                  this.setHtml(this.getTpl().apply(response.responseText));
            }                       
        } 
        ); 
    }
});

错误控制台

this.getTpl is not a function
[Break On This Error]   

this.setHtml(this.getTpl().apply(response.responseText));

success需要更新模板,但问题是 this.getTpl 在内联函数内部未定义success:function。它是在 之后定义的initcomponent。我需要在里面调用它success。有任何想法吗??

4

1 回答 1

1

它不是真正的父母。你不能爬上dom来得到它,但是......

Ext.define('casta.view.Intro', {
    extend: 'Ext.tab.Panel',
    tpl: '<p> {username} </p>',
    initComponent: function(){
        //Be sure to use the var keyword for planet earth, otherwise its declared as a global variable
        //var planetEarth = { name: "Earth", mass: 1.00 };
       //this.setHtml(this.getTpl().apply(planetEarth));
       var me = this;
         Ext.Ajax.request( 
        {    
            waitMsg: 'Bitte warten...', 
            url: 'http://localhost:8000/api/casta/user/?format=json', 

            success:function(response,options){ 
                //var responseData = Ext.util.JSON.decode(response.responseText); 
                  me.setHtml(me.getTpl().apply(response.responseText));
            }                       
        } 
        ); 
    }
});    

去阅读闭包。

于 2012-05-28T07:04:22.977 回答