绑定完成后执行操作

问题描述 投票:4回答:2

我写这部分是为了用选择控制器绑定OData信息:

var countrItems = new sap.ui.core.ListItem();
countrItems.bindProperty("key", "Land1");
countrItems.bindProperty("text", "Landx");
var CountrSelect = this.byId("CountrySelect");
CountrSelect.setModel(oModelTriptab);
CountrSelect.bindItems("/Countries", countrItems);

我想在绑定完成后执行一个动作(我想选择一些可以动态改变的默认值)。

sapui5
2个回答
4
投票

使用模型的requestCompleted事件处理程序来执行在更新模型数据后应立即执行的任何操作。

绑定本身应该是相当静态的(即它不会改变)所以你只对数据被更改时感兴趣


编辑这里是一个示例实现:

var that = this;
oModelTriptab.attachRequestCompleted(function(oEvent){
    var oSelect = that.byId("CountrySelect");
    oSelect.setSelectedKey("whatever");
});

有关更多信息,请参阅https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.Model.html#attachRequestCompleted


7
投票

将处理程序附加到Binding提供的事件:

<Select items="{
  path: '/Countries',
  events: {
    dataRequested: '.onCountriesRequested',
    dataReceived: '.onCountriesReceived',
    change: '.onCountriesChange'
  }
}">

这些事件不仅可以应用于ListBindings,还可以应用于所有绑定。注意:PropertyBindings不会触发任何请求,所以没有dataRequesteddataReceived

我想在绑定完成后执行一个操作。

在这种情况下,您可以将处理程序附加到changedataReceived事件,以通知有关“完整”绑定的信息。

与将处理程序附加到requestCompleted相比,上述方法更具描述性,最重要的是,特定于绑定。


列表,m.Table,m.Tree,...

或者,UI5为来自updateFinished的控件提供事件sap.m.ListBase。它类似于change事件,但提供了更多信息,例如额外的"Growing"原因,实际和条目总数。

<List
  updateFinished=".onCountriesUpdateFinished"
  items="..."
>
onCountriesUpdateFinished: function(event) {
  const reasonForUpdate = event.getParameter("reason"); // "Refresh", "Growing", "Filter", "Sort", "Context", ...
  const currentlyLoadedNumberOfCountries = event.getParameter("actual");
  const totalNumberOfCountries = event.getParamter("total") // Value of $count
  // ...
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.