1

我目前正在使用 Sencha Touch,Sencha Architect 3,使用名为 Pullrefresh 的 pluing 构建了一个简单的列表: https ://github.com/p5hema2/Sencha-PullRefresh-RefreshFn

我只能更新新的记录,但更新和删除的记录在我的商店中,但我的视图没有更新。所以我需要修改我的插件。在 Sencha Architect 中,我不知道如何解决这个问题。

有没有人有这方面的经验?修改插件

Ext.define('TP.extend.override.PullRefresh', {    override: 'Ext.plugin.PullRefresh',


onLatestFetched: function(operation) {
    var store           = this.getList().getStore(),
        oldRecords      = store.getData(),
        old_length      = oldRecords.length,
        newRecords      = operation.getRecords(),
        length          = newRecords.length,
        toInsert        = [],
        newRecordIds    = [],
        oldRecordsArr   = [],
        toRemove        = [],
        newRecord, newRecordIndex, oldRecord, i;


    for (i = 0; i < length; i++) {
        newRecord = newRecords[i];
        oldRecord = oldRecords.getByKey(newRecord.getId());


        newRecordIds.push(newRecord.getId());


        if (oldRecord) {
            oldRecord.set(newRecord.getData());
        } else {
            toInsert.push(newRecord);
        }


        oldRecord = undefined;
    }


    store.insert(0, toInsert);
    oldRecordsArr = store.getRange();
    for (i = 0; i < old_length; i++) {
        oldRecord = oldRecordsArr[i];
        newRecordIndex = newRecordIds.indexOf(oldRecord.getId());


        if (newRecordIndex == undefined || newRecordIndex == -1) {
            toRemove.push(oldRecord);
        }


        oldRecord = undefined;
    }
    store.remove(toRemove);
    }
});

上面的例子也是更新已删除的记录。

4

0 回答 0