I am implementing a Master-Detail App using SAPUI5, when open the app at first time, URL hash is empty, and I want set the hash to the first item in the master list, but I cannot fire the dataReceived event to decide the listLoading is done. Any idea?
manifest.json:
{
"sap.app": {
"dataSources": {
"mainService": {
"uri": "XXX",
"type": "JSON"
}
},
...
}
Master.view.xml:
<List items="{path: '/'}">
...
</List>
Master.controller.js
onInit : function () {
this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched, this);
}
/**
* If the master route was hit (empty hash) we have to set
* the hash to to the first item in the list as soon as the
* listLoading is done and the first item in the list is known
* @private
*/
_onMasterMatched : function() {
console.log(this._oList.getBinding("items") instanceof sap.ui.model.Binding) // return ture
this._oList.getBinding("items").attachEventOnce("dataReceived",
function(oData) {
//did not call
var oFirstListItem = this._oList.getItems()[0];
});
}
Ref: https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Binding.html#event:dataReceived
dataReceived
, the eventupdateFinished
works even with a JSONModel no matter when the data are actually received: stackoverflow.com/a/43970340/5846045 – Boghyon Hoffmann