我在调用 Ext.Ajax.request
时遇到程序范围问题。我需要能够从 ajax 回调函数访问周围的 Ext.data.Model
实例。实现这一目标的正确方法是什么?
我在 sencha touch 2 中这样定义数据模型:
Ext.define('AlbumsData', {
extend: 'Ext.data.Model',
requires: [
'Ext.Ajax'
],
config: {
fields: [
{name: 'someData', type: 'string'}
]
},
getData: function(){
Ext.Ajax.request({
url : '/somedata.json',
callback: function(options, success, response) {
//I want to access the surrounding model instance here and "this" certainly doesn't return the instance of the "Ext.data.Model" in which this getData() method is.
}
});
}
最佳答案
使用 scope
选项:
getData: function(){
Ext.Ajax.request({
url : '/somedata.json',
callback: function(options, success, response) {
//I want to access the surrounding model instance here and "this" certainly doesn't return the instance of the "Ext.data.Model" in which this getData() method is.
},
scope: this
});
}
关于javascript - Sencha touch 2 ajax 回调函数作用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24042020/