2012-05-28 47 views
0

當Ajax調用成功時,我需要更新sencha模板。示例代碼是像下面在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 inline函數裏面success:function不確定。它在initcomponent之後定義。我需要打電話給success。有任何想法嗎??

回答

1

它不是真正的父母。你不能在旅行中得到它,但...

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)); 
      }      
     } 
     ); 
    } 
});  

去閱讀關閉。