Extjs Restful Store,批量发送请求?
我创建了一个带有如下存储配置的网格组件:
//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 行并点击“删除”,则会向服务器发出 10 个删除请求。
例如,这就是我删除记录的方式:
/**
* 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,根据Ext.data.Store下的batch
文档,
如果 Store 是 RESTful,则 DataProxy 也是 RESTful,并且会为每条记录生成唯一的事务。
我希望这是我的配置问题。
注意:我尝试在 Ext.data 中使用
...没有希望listful
、encode
、writeAllFields
、encodeDelete
.JsonWriter
I created a Grid component with the store configuration like this:
//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
}
}
});
Note: Ignore the fireEvents. This store is being configured in a shared custom Grid Component.
However, I have one problem here: Whatever CRUD actions I did, I always come out with N requests to the server which is equal to N rows I selected. i.e., if I select 10 rows and hit Delete, 10 DELETE requests will be made to the server.
For example, this is how I delete records:
/**
* 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();
},
Note: The scope of "this" is a Grid Component.
So, is it suppose to be like that? Or my configuration problem?
I'm using Extjs 3.3.1, and according to the documentation of batch
under Ext.data.Store,
If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is generated for each record.
I wish this is my configuration problem.
Note: I tried with listful
, encode
, writeAllFields
, encodeDelete
in Ext.data.JsonWriter
... with no hope
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是对于那些可能想知道为什么它不是批处理的人:
至于文档所述,
如果您查看
/src/data/Store.js
中Ext.data.Store
的源代码,这是正确的,第 309 行,在
@constructor
就是为什么我意识到当我使用
restful
时,我的batch
永远不会更改为true
。Just for those who might wonder why it's not batch:
As for the documentation stated,
Which is true if you look into the source code of
Ext.data.Store
in/src/data/Store.js
Line 309, in
@constructor
And so this is why I realize when I use
restful
, mybatch
will never get changed totrue
.您正确阅读了文档;它应该是这样工作的。每当选择是否在网格上使用 RESTful 存储时,都需要考虑这一点。如果您需要批量操作,那么 RESTful 商店不是您的朋友。对不起。
You read the docs correctly; it is supposed to work that way. It's something to consider whenever choosing whether to use RESTful stores on your grids. If you're going to need batch operations, RESTful stores are not your friends. Sorry.