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

テンプレートを更新する必要がありますが、問題は、 this.getTplsuccessがインライン関数内で未定義になっていることsuccess:functionです。の後に定義されinitcomponentます。私はそれを内部で呼び出す必要がありますsuccess。何か案は??

4

1 に答える 1

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

閉鎖について読んでください。

于 2012-05-28T07:04:22.977 に答える