我有以下基类来处理所有请求
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作为回调?
答案 0 :(得分:2)
你需要传递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
});