【问题标题】:extjs store sometimes calling create instead of updateextjs store 有时会调用 create 而不是 update
【发布时间】:2016-04-01 08:44:20
【问题描述】:

我们在 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 个有效)拖到将立即更新存储的网格时,我们会收到服务器错误,因为我们没有为类似 URL 实现 POST 功能

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

这只是一个条目。

对于其他人来说是

/api/document_basket?_dc=1459498608941&{}

哪个有效。

仅拖动单个条目有效。

所以 ExtJS 正在发送一个带有 ID 的 POST 请求,它应该是一个 PUT 代替?这是为什么呢?

【问题讨论】:

    标签: javascript extjs extjs4


    【解决方案1】:

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

    原因是我在循环中向商店添加项目 - 所以在每次添加之后 - 比如说 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
    

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 2016-07-10
      • 1970-01-01
      • 2012-08-02
      • 2019-03-20
      • 2011-04-13
      相关资源
      最近更新 更多