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

标签 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: '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/

相关文章:

javascript - 回文检查器需要帮助

javascript - Codeigniter - Ajax 调用时出错 (404)

javascript - 我如何使用 jQuery ajax 函数发布凭证

Android:从回调中获取结果(联网KOUSH ION)

javascript - 如何查看有关服务器发送事件的错误?

javascript - 通过数组中的对象属性获取前三个对象

javascript - console.log - 写在位置栏中而不是控制台面板中

javascript - 动态元素上的 Jquery 选择器

php重定向 header 未通过ajax调用发送

android - Twitter 的回调 Url