1

我的 Rally 自定义数据存储不会更新。我遇到了 [this][1] 帖子中描述的问题。

我的场景是:我将向具有自定义数据存储的网格添加行。然后我对一个网格列进行排序,我添加的所有新行都被删除了。我的自定义商店没有什么花哨的,我尝试过 autoSync:true,但什么也没做。

自定义存储是否是只读的,因为对原始数据所做的任何更改都是暂时的,并且会被 reload() 删除?

这是我添加到拉力网格的商店

        me.customStore = Ext.create('Rally.data.custom.Store', { 
            data: customData,
            listeners:{
                load: function(customStore){
                    //do some stuff
                }
            }
        });
4

1 回答 1

1

I looked at the source code for the memory proxy and it makes sense why nothing was getting added or removed or updating correctly with the Rally.data.custom.Store store. You have to override the create and destroy methods of the memory proxy.

CURRENT MEMORY PROXY FUNCTIONS

These are functions that are used to create and destroy records for the memory proxy. As you can see, they dont create or destroy any records...

updateOperation: function(operation, callback, scope) {
    var i = 0,
        recs = operation.getRecords(),
        len = recs.length;

    for (i; i < len; i++) {
        recs[i].commit();
    }
    operation.setCompleted();
    operation.setSuccessful();

    Ext.callback(callback, scope || this, [operation]);
},    

create: function() {
    this.updateOperation.apply(this, arguments);
},

destroy: function() {
    this.updateOperation.apply(this, arguments);
},

CORRECT MEMORY PROXY SETUP

Below is how to instantiate a custom store that will actually add and remove records in the custom store

    me.customStore = Ext.create('Rally.data.custom.Store', {
        data: //customData
        model: //modelType
        autoSync:true,
        proxy: {
            type:'memory',
            create: function(operation) {
                var me = this;
                operation.getRecords().forEach(function(record){
                    console.log('adding record', record);
                    me.data.push(record);
                });
                this.updateOperation.apply(this, arguments);
            },
            destroy: function(operation) {
                var me = this;
                operation.getRecords().forEach(function(record){
                    console.log(record);
                    for(var i = 0;i<me.data.length;++i){
                        if(/*me.data[i] == record*/ ){
                            me.data.splice(i, 1);
                            return;
                        }
                    }
                });
                this.updateOperation.apply(this, arguments);
            }
        },
        listeners://listener stuff here
    });
于 2014-07-24T19:41:51.917 回答