2014-03-13 74 views
0

我有一個存儲配置了代理POST數據到服務器。我動態地向這家商店添加記錄。在商店上調用sync()方法後,數據被髮送到服務器。但看着網絡流量,我發現整個記錄數據都被髮送出去了。如何配置商店僅發送單個數據(如僅記錄的ID)?Ext JS Store POST請求過濾參數

我試圖seeting的WriteAllFields屬性設置爲false在連接到代理的JSON writter但這並沒有幫助

我自己也嘗試這種方法:Ext.JS Prevent Proxy from sending extra fields但請求甚至沒有進行

var documentStore = Ext.getStore('Document'); 
var trashStore = Ext.getStore('TrashDocuments'); 

documentStore.each (function(record) { 

    console.debug(record); 

    //record.phantom = true; 
    //record.setDirty(); 

    trashStore.add(record); 
    documentStore.remove(record); 
}); 


var newWriter = Ext.create('Ext.data.writer.Json',{ 
    getRecordData: function(record){ 
     return {'id':record.data.id}; 
    } 
}); 

trashStore.getProxy().setWritter(newWritter); 

trashStore.sync({ 
      success: function() 
      { 
       console.debug("success!!"); 
      }, 
      failure: function() 
      { 
       console.debug("failed..."); 
      }, 
      callback: function() 
      { 
       console.debug("calling callback"); 
      }, 
      scope: this 
     }); 

console.debug("END"); 
+0

你是如何修改記錄的?你有沒有可能在上面設置髒標誌? – lascort

+0

我將記錄從另一個商店添加到此商店,然後調用sync() – Jacob

回答

1

writeAllFields配置不起作用,因爲這隻對非幻影記錄有意義;虛擬(新)記錄的任何字段將被視爲「已更改」,因此包含在請求數據包中。

要排除請求中包含的特定字段,請將persist:false添加到您不想包含的字段中。

這就是說,我不太明白爲什麼你只想寫一個新添加的記錄的ID。除非你明確地讓Ext JS爲你創建這些ID,否則你實際上將要發送給服務器的是什麼?我不知道你的用例,但通常希望持久層(例如數據庫)爲你的記錄分配標識符。

+0

我只希望將ID列表發送到服務器,它們都是... – Jacob

+0

但您知道這些ID是針對新模型實例動態生成的,對?您是否使用Ext.data.IdGenerator子類之一? – existdissolve

+0

他們不生成我知道他們,因爲我已經從另一個現有的商店添加他們。 – Jacob