我用这样的商店配置创建了一个 Grid 组件:
//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。此商店正在共享自定义网格组件中进行配置。
但是,我在这里有一个问题:无论我做了什么 CRUD 操作,我总是向服务器发出 N 个请求,这等于我选择的 N 行。即,如果我选择 10 行并点击 Delete,将向服务器发出 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”的范围是一个网格组件。
那么,它应该是这样的吗?还是我的配置问题?我正在使用 Extjs 3.3.1,根据batch
Ext.data.Store 下的文档,
如果 Store 是 RESTful,则 DataProxy 也是 RESTful,并且为每条记录生成一个唯一的事务。
我希望这是我的配置问题。
注意:我尝试使用listful
, encode
, writeAllFields
, encodeDelete
in Ext.data.JsonWriter
... 没有希望