[英]SAPUI5 model loading
有什么方法可以知道何时加载模型?
例:
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);
}
...
在这种情况下,定义了模型实例,但是它包含空对象,因为没有数据被加载。
如果我用以下命令包装console.log方法:
setTimeout(function() {
console.log(sap.ui.getCore().byId("app").getModel("mymodel"));
}, 0);
然后可以正确加载模型数据,但是我想要比使用setTimeout更可靠的东西。
sap.ui.model.Model类具有一个名为requestCompleted
( link )的事件。 因此,您可以使用方法attachRequestCompleted
( link )将函数附加到该事件:
this.model.attachRequestCompleted(function(oEvent){
var model = oEvent.getSource();
console.log(model);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.