Extjs 通过 JSONP 读取,但在写入时崩溃 - 对象不支持 属性 或方法 'writeRecords'

Extjs reads via JSONP, but crashes when writing - Object doesn't support property or method 'writeRecords'

我想知道是否有人可以提供帮助,因为我正在绕圈子。

我有以下代码摘录。虽然发生了什么,但它读起来很好,但是如果我调用 sync() (在保存按钮中)它会崩溃:

对象不支持 属性 或方法 'writeRecords'

Ext.define('Objectives', {
    extend: 'Ext.data.Model',
    fields: ['Release', 'Team', 'Objective']
});

this.store = Ext.create('Ext.data.Store', {
    storeId: 'storeGrid',
    model: 'Objectives',
    proxy: {
        type: 'jsonp',
        url : 'http://mywebsite',
        api: {
            create  : 'http://mywebsite/write.php',
            read    : 'http://mywebsite/read.php',
            update  : 'http://mywebsite/write.php',
            destroy : 'http://mywebsite/read.php'
        }
    }
});

this.myGrid = this.add( {
    xtype: 'gridpanel',
    title: 'My Stuff',
    store: this.store,
    dockedItems:[{
        xtype: 'toolbar',
        dock: 'top',
        items: [{
            xtype: 'button',
            text: 'Add row',
            listeners: {
                click: {
                    fn: function () {
                        var newRow = new Objectives();
                        this.store.insert(0, newRow);
                    },
                    scope: this
                },
                scope: this
            },
            scope: this
        },
        {
            xtype: 'button',
            text: 'Save',
            listeners: {
                click: {
                    fn: function () {
                        this.store.sync();
                    },
                    scope: this
                },
                scope: this
            },
            scope: this
              }]
    }],
    columns: [
        { text: 'Release', dataIndex: 'Release' },
        { text: 'Team', dataIndex: 'Team' },
        { text: 'Objective', dataIndex: 'Objective' }
    ]
});

我的 php 代码目前两者都相同,即:

  $callback = trim($_GET["callback"]);
  if ($callback) {
    header('Content-Type: text/javascript');
    echo $callback . '(' . $output . ');';
} else {
    header('Content-Type: application/x-json');
    echo $output;
}

我很确定它与范围有关,但我无法理解:(

此外,我知道我正在复制主要的 URL (http://mywebsite),因为如果我不这样做,它会出现以下错误: 无法获取 属性 'errorType' 未定义或空引用

再一次,欢迎任何建议。

感谢您的帮助。

是的,这似乎只是一个范围相关的错误。

这是工作代码。它在调用 sync() 方法时发出网络请求,没有任何控制台错误。 (404 错误是由于虚假网址造成的)

    Ext.define('Objectives', {
        extend: 'Ext.data.Model',
        fields: ['Release', 'Team', 'Objective']
    });

    var store = Ext.create('Ext.data.Store', {
        storeId: 'storeGrid',
        model: 'Objectives',
        autoLoad: true,
        proxy: {
            type: 'jsonp',
            url: 'http://mywebsite',
            api: {
                create: 'https://mywebsite/write.php',
                read: 'https://mywebsite/read.php',
                update: 'https://mywebsite/write.php',
                destroy: 'https://mywebsite/read.php'
            }
        }
    });

    Ext.create('Ext.grid.Panel', {
        title: 'My Stuff',
        itemId: 'mygrid',
        store: store,
        columns: [{
            text: 'Release',
            dataIndex: 'Release'
        }, {
            text: 'Team',
            dataIndex: 'Team'
        }, {
            text: 'Objective',
            dataIndex: 'Objective'
        }],

        dockedItems: [{
            xtype: 'toolbar',
            dock: 'top',
            items: [{
                xtype: 'button',
                text: 'Add row',
                handler: function (button) {
                    var newRow = Ext.create('Objectives', {});
                    button.up('#mygrid').store.insert(0, newRow);
                }
            }, {
                xtype: 'button',
                text: 'Save',
                handler: function (button) {
                    button.up('#mygrid').store.sync();
                }
            }]
        }]
    });

勾选 fiddle: Fiddle