当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
我需要更新模板,但问题是内联函数success:function
中未定义this.getTpl。它是在initcomponent
之后定义的。我需要在success
内调用它。任何想法??
答案 0 :(得分: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));
}
}
);
}
});
阅读闭包。