如何在Aviarc中快速更新数据集列

时间:2012-10-26 02:25:31

标签: aviarc

例如,我有一个迭代数据集的按钮,并将一个字段设置为一个值。

<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行的数据集,并且在运行时有明显的延迟。

还有其他办法吗?

1 个答案:

答案 0 :(得分: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();