extjs 存储有时调用创建而不是更新

extjs store sometimes calling create instead of update

我们在 ExtJS 4.2 中有以下商店:

Ext.define('Example.store.BasketDocuments', {
    extend: 'Ext.data.Store',
    model: 'Example.model.Document',
    autoLoad: true,
    autoSync: true,
    sorters: [
    {
        property: 'doc_type',
        direction: 'ASC'
    }
    ],
    proxy: {
    type: 'rest',
    url: baseUrl + 'document_basket',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json;charset=utf-8'
    },
    reader: {
        type: 'json',
        root: 'items'
    },
    writer: {
        type: 'json'
    },
    actionMethods: {create: "POST", read: "GET", update: "PUT", destroy: "DELETE"}
    }
});

它附加到具有拖放功能的网格。

当我们将大约 10 个文件(其中 9 个有效)拖到将立即更新商店的网格时,我们会收到服务器错误,因为我们没有为 [=31= 实现 POST 函数]就像

/api/document_basket/1964?_dc=1459498608890&{}

这只是一个条目。

对于其他人来说

/api/document_basket?_dc=1459498608941&{}

有效。

仅拖动该单个条目即可。

所以 ExtJS 正在发送一个 POST 请求,其 ID 在 URL 中,应该是 PUT?这是为什么?

我能够在我的项目中解决这个问题。

原因是我在循环中向商店添加项目 - 所以在每次添加之后 - 比如说 14 个文件 - 同步完成。

我发现有 105 个请求,正好是 1+2+3+4+5+6+7+8+9+10+11+12+13+14 所以这导致了竞争条件。

解决方案是在循环之前禁用同步:

onBeforeDropItem: function (node, data, overModel, dropPosition, dropHandlers, eOpts) {
    dropHandlers.cancelDrop();

    var store = Ext.getStore('BasketDocuments');

    store.suspendAutoSync(); // new

    if (node.id != 'documenttreepanel-body') {
        Ext.Array.each(data.records, function (r, index) {
            r = r.copy();
            r.phantom = true;
            r.data.id = null;
            r.data.download_size = 1;
            r.data.download_type = 1;

            if (r.data.doc_type == 1) {
                if (r.data.count == 0) {
                    Ext.create('Ext.window.MessageBox').show({
                        title: Ext.ux.Translate.get('Info'),
                        msg: Ext.ux.Translate.get('Ordner') + '<b>' + r.data.name + '</b>' + Ext.ux.Translate.get(' Is empty and cannot be added ') + '.',
                        buttons: Ext.Msg.OK,
                        modal: true
                    });
                } else {
                    store.add(r);
                }
            } else {
                store.add(r);
            }
        });
    }

    store.sync(); // new
    store.resumeAutoSync(); // new