Download SAPUI5 Model

Is there any way to know when a model is loaded?

Example:

sap.ui.controller("myapp.MyViewController", { onInit: function() { this.router = sap.ui.core.UIComponent.getRouterFor(this); this.router.attachRoutePatternMatched(this._handleRouteMatched, this); this.model = sap.ui.getCore().byId("app").getModel("mymodel"); }, onAfterRendering: function() { console.log(this.model); } ... 

In this case, the model instance is defined, but contains an empty object because the data is not loading.

If I end the console.log method with

 setTimeout(function() { console.log(sap.ui.getCore().byId("app").getModel("mymodel")); }, 0); 

then the model data loads correctly, but I would like to get something more reliable than using setTimeout.

+5
source share
1 answer

The sap.ui.model.Model class has an event called requestCompleted ( link ). Thus, you can attach a function to this event using the attachRequestCompleted method ( link ):

 this.model.attachRequestCompleted(function(oEvent){ var model = oEvent.getSource(); console.log(model); }); 
+5
source

Source: https://habr.com/ru/post/1213462/


All Articles