javascript - Extjs Restful Store,批量发送请求?

标签 javascript rest extjs store extjs3

我创建了一个 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 行并点击删除,将向服务器发出 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,根据 Ext.data.Store 下的 batch 的文档,

If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is generated for each record.

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

注意:我尝试在 中使用 listfulencodewriteAllFieldsencodeDelete Ext.data.JsonWriter...没有希望

最佳答案

仅针对那些可能想知道为什么它不是批处理的人:

至于说明的文档,

If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is generated for each record.

如果您在 /src/data/Store.js 中查看 Ext.data.Store 的源代码,这是正确的

第309行,在@constructor

// If Store is RESTful, so too is the DataProxy
if (this.restful === true && this.proxy) {
    // When operating RESTfully, a unique transaction is generated for each record.
    // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only.
    this.batch = false;
    Ext.data.Api.restify(this.proxy);
}

这就是为什么我意识到当我使用 restful 时,我的 batch 永远不会更改为 true

关于javascript - Extjs Restful Store,批量发送请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4386701/

相关文章:

javascript - 如果我刷新几次,为什么我的应用程序会在 Chrome 中崩溃?

javascript - 拖放到右侧(或左侧)的 <div>?

javascript - 从 javascript 捕获 window.open

java - Sonar WebService API - 资源端点不返回指标

java - 如何将多个大文件流式传输到 jetty

java - 调用 REST API 的次数

ExtJS:如何拥有具有多个根的 TreePanel?

javascript - JS 中 "this"的 jQuery 等价物是什么?

extjs - 记住刷新 extjs 网格中的选定行后

java - Sencha GXT 网格过滤器速度很慢。我能让它们快点吗?