3

次のようなストア構成でグリッドコンポーネントを作成しました。

    //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は無視してください。このストアは、共有カスタムグリッドコンポーネントで構成されています。

ただし、ここで1つの問題があります。どの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」のスコープはグリッドコンポーネントです。

それで、それはそのようなことを想定していますか?または私の構成の問題?私はExtjs3.3.1を使用していますがbatch、Ext.data.Storeのドキュメントによると、

StoreがRESTfulの場合、DataProxyもRESTfulであり、レコードごとに一意のトランザクションが生成されます。

これが私の構成の問題だといいのですが。

注:私は、、、、で...で試しましたが、希望はありませんlistfulでしたencodewriteAllFieldsencodeDeleteExt.data.JsonWriter

4

2 に答える 2

6

なぜバッチではないのか疑問に思う人のために:

記載されているドキュメントについては、

StoreがRESTfulの場合、DataProxyもRESTfulであり、レコードごとに一意のトランザクションが生成されます。

Ext.data.Storeのソースコードを調べれば、これは真実です。/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

ドキュメントを正しく読んだ。それはそのように機能することになっています。グリッドでRESTfulストアを使用するかどうかを選択するときは常に考慮する必要があります。バッチ操作が必要な場合、RESTfulストアは友達ではありません。ごめん。

于 2010-12-09T00:11:31.723 に答える