Extjs Sencha架构师-修改插件
我目前与Sencha Touch、Sencha Architect 3合作, 使用名为Pullrefresh的pluing构建了一个简单列表: 我只能更新新记录,但更新和删除的记录在我的存储中,但不随视图更新。所以我需要修改我的插件。在Sencha Architect中,我不知道如何解决这个问题 有人有这方面的经验吗?修改插件Extjs Sencha架构师-修改插件,extjs,touch,Extjs,Touch,我目前与Sencha Touch、Sencha Architect 3合作, 使用名为Pullrefresh的pluing构建了一个简单列表: 我只能更新新记录,但更新和删除的记录在我的存储中,但不随视图更新。所以我需要修改我的插件。在Sencha Architect中,我不知道如何解决这个问题 有人有这方面的经验吗?修改插件 Ext.define('TP.extend.override.PullRefresh', { override: 'Ext.plugin.PullRefresh'
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);
}
});
Ext.define('TP.extend.override.PullRefresh',{override:'Ext.plugin.PullRefresh',
onLatestFetched:函数(操作){
var store=this.getList().getStore(),
oldRecords=store.getData(),
old_length=oldRecords.length,
newRecords=operation.getRecords(),
长度=newRecords.length,
toInsert=[],
NewRecordId=[],
oldRecordsArr=[],
toRemove=[],
新记录,新记录索引,旧记录,i;
对于(i=0;i
上面的示例也用于更新已删除的记录