3

我用这样的商店配置创建了一个 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,根据batchExt.data.Store 下的文档,

如果 Store 是 RESTful,则 DataProxy 也是 RESTful,并且为每条记录生成一个唯一的事务。

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

注意:我尝试使用listful, encode, writeAllFields, encodeDeletein Ext.data.JsonWriter... 没有希望

4

2 回答 2

6

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

至于文件所述,

如果 Store 是 RESTful,则 DataProxy 也是 RESTful,并且为每条记录生成一个唯一的事务。

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

第 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.

于 2010-12-09T07:47:37.813 回答
2

您正确阅读了文档;它应该以这种方式工作。It's something to consider whenever choosing whether to use RESTful stores on your grids. 如果您需要批量操作,RESTful 存储不是您的朋友。对不起。

于 2010-12-09T00:11:31.723 回答