控制器的Extjs回调函数
我有以下处理所有请求的基类控制器的Extjs回调函数,extjs,extjs4,extjs4.1,extjs4.2,Extjs,Extjs4,Extjs4.1,Extjs4.2,我有以下处理所有请求的基类 makeRequest: function(mydata) { Ext.Ajax.request({ url: './handler.php', method: 'GET', scope: this, params: { data: mydata }, callback: this.myResponse, success: f
makeRequest: function(mydata) {
Ext.Ajax.request({
url: './handler.php',
method: 'GET',
scope: this,
params: {
data: mydata
},
callback: this.myResponse,
success: function(xhr, params) {
console.log('Success');
},
failfure: function(xhr, params) {
console.log('Failure');
}
});
}
我的控制器里有
.............
requires: [
'Test.libs.Request'
],
............
onItemClick: function() {
var objCallback = Ext.create('Test.libs.Request', {
scope: this
});
objCallback.makeRequest(1);
},
myResponse: function(options, success, response) {
console.log(response);
}
在成功执行后,如何以回调的形式访问控制器的myResponse 您需要传递fn和范围,例如:
Ext.create('Test.libs.Request', {
callback: this.myResponse
scope: this
});
// You need to get a reference to those passed params inside your request method.
Ext.Ajax.request({
url: './handler.php',
method: 'GET',
scope: passedScope,
params: {
data: mydata
},
callback: passedCallback
});
目前,我将参数传递给objCallback.makeRequest(1,this.myResponse,this)用于回调和作用域,它可以工作。是的,这样就可以了。