2016-04-01 31 views
1

我們在ExtJS的4.2以下商店:ExtJS的存儲有時叫創造,而不是更新

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發送一個帶有URL的POST請求,該請求應該是一個PUT?這是爲什麼?

回答

0

我能在我的項目中解決這個問題。

原因是我在一個循環中將商品添加到商店 - 所以在每次添加之後 - 比方說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 
相關問題