次のようなストア構成でグリッドコンポーネントを作成しました。
//Create the store
config.store = new Ext.data.Store({
restful: true,
autoSave: false,
batch: true,
writer: new Ext.data.JsonWriter({
encode: false
}),
reader: new Ext.data.JsonReader({
totalProperty: 'total',
root: 'data',
fields: cfg.fields
}),
proxy: new Ext.data.HttpProxy({
url:cfg.rest,
listeners:{
exception: {
fn: function(proxy, type, action, options, response, arg) {
this.fireEvent('exception', proxy, type, action, options, response, arg);
},
scope: this
}
}
}),
remoteSort: true,
successProperty: 'success',
baseParams: {
start: 0,
limit: cfg.pageSize || 15
},
autoLoad: true,
listeners: {
load: {
fn: function() {
this.el.unmask();
},
scope: this
},
beforeload: {
fn: function() {
this.el.mask("Working");
},
scope: this
},
save: {
fn: function(store, batch, data) {
this.el.unmask();
this.fireEvent('save', store, batch, data);
},
scope: this
},
beforewrite: {
fn: function(){
this.el.mask("Working...");
},
scope: this
}
}
});
注:fireEventsは無視してください。このストアは、共有カスタムグリッドコンポーネントで構成されています。
ただし、ここで1つの問題があります。どのCRUDアクションを実行しても、選択したN行に等しいサーバーへの要求が常にN個発生します。つまり、10行を選択して[削除]をクリックすると、サーバーに対して10個のDELETE要求が行われます。
たとえば、これは私がレコードを削除する方法です:
/**
* Call this to delete selected items. No confirmation needed
*/
_deleteSelectedItems: function() {
var selections = this.getSelectionModel().getSelections();
if (selections.length > 0) {
this.store.remove(selections);
}
this.store.save();
this.store.reload();
},
注:「this」のスコープはグリッドコンポーネントです。
それで、それはそのようなことを想定していますか?または私の構成の問題?私はExtjs3.3.1を使用していますがbatch
、Ext.data.Storeのドキュメントによると、
StoreがRESTfulの場合、DataProxyもRESTfulであり、レコードごとに一意のトランザクションが生成されます。
これが私の構成の問題だといいのですが。
注:私は、、、、で...で試しましたが、希望はありませんlistful
でしたencode
writeAllFields
encodeDelete
Ext.data.JsonWriter