Javascript Sencha touch 2 ajax回调函数作用域
调用Javascript Sencha touch 2 ajax回调函数作用域,javascript,ajax,callback,scope,sencha-touch-2,Javascript,Ajax,Callback,Scope,Sencha Touch 2,调用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:
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.
}
});
}
在进入Ext.AJAX上下文之前,将您的
保存在变量中:
getData: function(){
var scope = this;
Ext.Ajax.request({
url : '/somedata.json',
callback: function(options, success, response) {
scope.get('someData'); //you can now use scope here
}
});
}
在进入Ext.AJAX上下文之前,将您的保存在变量中:
getData: function(){
var scope = this;
Ext.Ajax.request({
url : '/somedata.json',
callback: function(options, success, response) {
scope.get('someData'); //you can now use scope here
}
});
}
使用范围
选项:
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
});
}
使用范围
选项:
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
});
}
谢谢!现在我可以使用这个
来访问周围的实例环境。谢谢!现在,我可以使用这个
来访问周围的实例环境。我已经尝试过了,但它不起作用<代码>范围:在这种情况下,这个
是正确的方法。我已经尝试过了,但它不起作用<代码>范围:在这种情况下,这是正确的方法。