Extjs Restful Store,批量发送请求? [英] Extjs Restful Store, Sending request in Batch?

查看:132
本文介绍了Extjs Restful 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',
字段: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);
},
范围:这个
}
}
}),
remoteSo rt:true,
successProperty:'success',
baseParams:{
start:0,
limit:cfg.pageSize || 15
},
autoLoad:true,
listeners:{
load:{
fn:function(){
this.el.unmask() ;
},
范围:
},

beforeload:{
fn:function(){
this.el.mask 加工);
},
范围:
},
save:{
fn:function(store,batch,data){
this.el.unmask ();
this.fireEvent('save',store,batch,data);
},
范围:此
},

beforewrite:{
fn:function(){
this.el.mask 加工...);
},
范围:此
}

}
});

注意:忽略fireEvent。这个商店正在配置在共享的自定义网格组件中。



但是,我在这里有一个问题:无论我做了什么CRUD操作,我总是出现N个请求服务器等于我选择的N行。即,如果我选择10行并按Delete,则会向服务器发送10个DELETE请求。



例如,这是我如何删除记录:

  / ** 
*调用此选项删除所选项目。不需要确认
* /
_deleteSelectedItems:function(){
var choices = this.getSelectionModel()。getSelections();
if(choices.length> 0){
this.store.remove(choices);
}
this.store.save();
this.store.reload();
},

注意:this的范围是网格组件。 p>

那么,假设是这样吗?还是我的配置问题?
我使用Extjs 3.3.1,根据Ext.data.Store下的批处理文件


如果商店是RESTful的,DataProxy也是RESTful的,每个记录都会生成一个独特的交易。


我希望这是我的配置问题。



注意:我尝试使用 listful encode writeAllFields encodeDelete in Ext.data.JsonWriter ...无希望

解决方案

您正确阅读文档;这应该是这样工作的。每当选择是否在网格上使用RESTful商店时,都需要考虑一下。如果您需要批量操作,RESTful商店不是您的朋友。对不起。


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

解决方案

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.

这篇关于Extjs Restful Store,批量发送请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆