2016-04-01 7 views
1

Wir haben folgende Speicher in ExtJS 4.2:extjs speichern manchmal statt Update Aufruf erstellen

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"} 
    } 
}); 

Es wird zu einem Gitter mit Drag angebracht ist und Drop-Funktionalität.

Wenn wir um 10 Dateien ziehen (für 9 es funktioniert) an das Netz, die den Laden sofort aktualisieren würde, erhalten wir einen Serverfehler, weil wir die POST-Funktion für URLs nicht implementieren wie

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

Dies ist nur für einen Eintrag.

Für die anderen wäre es

/api/document_basket?_dc=1459498608941&{} 

sein, die funktioniert.

Das Ziehen nur dieses einen Eintrags funktioniert.

Also ExtJS sendet eine POST-Anfrage mit einer ID in der URL, die stattdessen ein PUT sein sollte? Warum das?

Antwort

0

Ich konnte dies in meinem Projekt beheben.

Grund war, dass ich Elemente zum Laden in einer Schleife hinzufügte - so nach jedem Hinzufügen von - sagen wir 14 Dateien - eine Synchronisierung wurde gemacht.

Ich entdeckte, dass es 105 Anfragen gab, was nur 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 war.

Lösung ist die Synchronisierung vor der Schleife zu deaktivieren:

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 
Verwandte Themen