2012-05-28 8 views
0

아약스 호출이 성공하면 sencha 템플릿을 업데이트해야합니다. 샘플 코드는 내가 템플릿을 업데이트해야 successSencha에서 부모 개체에 액세스

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

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

오류 콘솔
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)); 
      }      
     } 
     ); 
    } 
}); 

아래처럼하지만 문제는 인라인 함수 success:function 내부 정의의 해당 this.getTpl입니다. 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)); 
      }      
     } 
     ); 
    } 
});  

최대 닫힙니다.

관련 문제