2013-04-11 61 views
4

如何在一次POST調用中將我的整個商店數據發送到服務器? 它可能是json格式。立即將Extjs商店的所有記錄發送到服務器

謝謝。

更新:

這是我的店鋪代碼:

Ext.define('App.store.consultorio.Receita', { 
    extend: 'Ext.data.Store', 
    model: 'App.model.consultorio.Receita', 
    autoLoad: false, 
    proxy: { 

     type: 'rest', 
     reader: { 
      type: 'json' 
     }, 
     writer: { 
      type: 'json' 
     }, 
     url: 'consultas/receita.json' 
    } 
}); 

回答

4

您可以設置每個記錄在店裏髒的,然後調用同步()

store.each(function(record){ 
    record.setDirty(); 
}); 

store.sync(); 

而且,你的店是使用RESTful代理,默認情況下不會批量操作。見http://docs.sencha.com/ext-js/4-2/#!/api/Ext.data.proxy.Rest-cfg-batchActions

你的店應該是這樣的:

Ext.define('App.store.consultorio.Receita', { 
    extend: 'Ext.data.Store', 
    model: 'App.model.consultorio.Receita', 
    autoLoad: false, 
    proxy: { 

     type: 'rest', 
     batchActions: true, //<------ 
     reader: { 
      type: 'json' 
     }, 
     writer: { 
      type: 'json' 
     }, 
     url: 'consultas/receita.json' 
    } 
}); 
+0

但是,這將要求每個記錄服務器的方法。 – Beetlejuice 2013-04-11 18:21:38

+0

否,AJAX代理的默認值是類似類型的批量操作。請參閱:http://docs.sencha.com/ext-js/4-2/#!/api/Ext.data.proxy.Ajax-cfg-batchActions – James 2013-04-11 18:27:11

+0

這是結果: http:// localhost:3000 /consultas/receita.json/2?_dc=1365705540725 http:// localhost:3000/consultas/receita.json/3?_dc = 1365705540836 http:// localhost:3000/consultas/receita.json/4 ?_dc = 1365705540923 – Beetlejuice 2013-04-11 18:41:58