質問

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

    //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の削除リクエストがサーバーに行われます。

たとえば、これがレコードを削除する方法です。

/**
 * 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を使用していますが、 batch ext.data.storeの下、

ストアが安らかな場合、Dataproxyも安らかであり、各レコードに対して一意のトランザクションが生成されます。

これが私の構成の問題であることを願っています。

注:一緒に試してみました listful, encode, writeAllFields, encodeDeleteExt.data.JsonWriter...希望がない

役に立ちましたか?

解決

ドキュメントを正しく読みます。そのように機能するはずです。グリッドで安らかな店を使用するかどうかを選択するときはいつでも考慮すべきものです。バッチオペレーションが必要な場合は、Restful Storeは友達ではありません。ごめん。

他のヒント

なぜそれがバッチではないのか疑問に思うかもしれない人のために:

述べられているドキュメントについては、

ストアが安らかな場合、Dataproxyも安らかであり、各レコードに対して一意のトランザクションが生成されます。

のソースコードを調べると、これは真実です Ext.data.Store/src/data/Store.js

309行、in @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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top