有什么方法可以知道什么时候加载模型吗?
示例:
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更可靠的东西。
发布于 2015-02-16 14:38:05
类sap.ui.model.Model有一个名为requestCompleted (链接)的事件。因此,您可以使用attachRequestCompleted (链接)方法向该事件附加一个函数:
this.model.attachRequestCompleted(function(oEvent){
var model = oEvent.getSource();
console.log(model);
});https://stackoverflow.com/questions/28543207
复制相似问题