1

例如,我有一个按钮,它遍历数据集并将一个字段设置为一个值。

<button left="10" width="100" bottom="12" height="32" label="Select All" enabled-if-dataset="data">
    <when event="onClick" xmlns="urn:aviarc:widget:com.aviarc.toronto.widget.core.action:1">
        <dataset:dataset-iterator dataset="data">
            <set-field field="data.selected" value="y"/>
        </dataset:dataset-iterator>
    </when>
</button>

这适用于较小的数据集,但现在我有一个包含 400 行的数据集,并且在运行时有明显的延迟。

还有另一种方法可以做到这一点吗?

4

1 回答 1

1

我建议这样做的方法是通过以下算法:

  • 在绑定到记录表的数据集上禁用相关事件
  • 使用字段更新进行迭代
  • 重新启用数据集事件
  • 触发刷新记录表的事件

我会将更新包装到 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();
于 2012-10-26T02:59:47.783 回答