gpt4 book ai didi

javascript - Sencha touch 2 ajax 回调函数作用域

转载 作者:行者123 更新时间:2023-11-30 10:15:30 27 4
gpt4 key购买 nike

我在调用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com