如何在不刷新模型的情况下批量设置setProperty()?

时间:2018-11-29 14:03:26

标签: odata sapui5 refresh

我有一个默认的OData Model V2,我想一次更新所有属性。

每次使用setProperty()方法时,模型都会刷新自身,并且调用太多方法会导致一些性能问题。

在每次调用setProperty()方法并最终刷新模型时,如何设置更改而不刷新模型?

    onAccept: function (oEvent) {
        var oModel = this.getOwnerComponent().getModel();
        oModel.setProperty("/QuoteItemSet(guid'" + this._sTliKey + "')/acceptedRateClass", true);
        oModel.setProperty("/QuoteItemSet(guid'" + this._sTliKey + "')/workflowStatus", "02");
        oModel.setProperty("/QuoteItemSet(guid'" + this._sTliKey + "')/accepted", true);
        oModel.setProperty("/QuoteItemSet(guid'" + this._sTliKey + "')/approvedRate", this._nApprovedRateValue);
        oModel.setProperty("/QuoteItemSet(guid'" + this._sTliKey + "')/approvedRateOnEdit", this._nApprovedRateValue);

    },

1 个答案:

答案 0 :(得分:0)

您可以使用方法setRefreshAfterChange()定义是否在更改操作之后更新所有绑定。用refresh()完成所有更改以检查所有绑定中是否有更新的数据后,不要忘记刷新模型。

oModel.setRefreshAfterChange(false);
[set properties...]
oModel.refresh();