我建议这样做的方法是通过以下算法:
- 在绑定到记录表的数据集上禁用相关事件
- 使用字段更新进行迭代
- 重新启用数据集事件
- 触发刷新记录表的事件
我会将更新包装到 Javascript 操作小部件中。下面的提取来自 Aviarc 3.6,我在其中做类似的事情(来自 run 方法),但您应该能够根据需要对其进行调整:
/* disable all events on the target dataset which would most likely trigger some widget behaviours */
var dsEvents = [
"ONDATASETCHANGED"
,"ONDATACHANGED"
,"ONLOCALDATACHANGED"
,"ONCONTENTSREPLACED"
,"ONCURRENTROWCHANGED"
,"ONROWCREATED"
,"ONROWDELETED"
,"ONROWADDED"
,"ONCURRENTROWDELETED"
,"ONROWCOMMITACTIONCHANGED"
,"ONCURRENTROWCOMMITACTIONCHANGED"
,"ONROWFIELDCHANGED"
,"ONCURRENTROWFIELDCHANGED"
];
var events = toDS.getEvents();
for (var i = 0, count = dsEvents.length; i < count; i++) {
events.getEventByName(dsEvents[i]).disable();
}
toDS.deleteAllRows();
fromDS.getAllRows().doLoop(function(fromDSRow) {
if (doFiltering) {
if (fromDSRow.getField(userIDField) == userID) {
this._copyRow(fromDSRow, toDS.createRow());
}
} else {
this._copyRow(fromDSRow, toDS.createRow());
}
}, this);
toDS.reset();
/* enable all events back */
for (var i = 0, count = dsEvents.length; i < count; i++) {
events.getEventByName(dsEvents[i]).enable();
}
/* trigger refresh on the widgets as if we just updated ds via ajax */
toDS.onContentsReplaced.fireEvent();
toDS.onDataChanged.fireEvent();
toDS.onDatasetChanged.fireEvent();