我写这部分是为了用选择控制器绑定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);
我想在绑定完成后执行一个动作(我想选择一些可以动态改变的默认值)。
使用模型的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
将处理程序附加到Binding提供的事件:
<Select items="{
path: '/Countries',
events: {
dataRequested: '.onCountriesRequested',
dataReceived: '.onCountriesReceived',
change: '.onCountriesChange'
}
}">
这些事件不仅可以应用于ListBindings,还可以应用于所有绑定。注意:PropertyBindings不会触发任何请求,所以没有dataRequested
或dataReceived
。
我想在绑定完成后执行一个操作。
在这种情况下,您可以将处理程序附加到change
或dataReceived
事件,以通知有关“完整”绑定的信息。
与将处理程序附加到requestCompleted
相比,上述方法更具描述性,最重要的是,特定于绑定。
或者,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
// ...
}