小编nic*_*man的帖子

SAPUI5模型加载

有什么方法可以知道什么时候加载模型?

例:

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);
    }
...
Run Code Online (Sandbox Code Playgroud)

在这种情况下,定义了模型实例,但它包含空对象,因为没有加载数据.

如果我用:包装console.log方法:

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

然后模型数据被正确加载,但我想比使用setTimeout更可靠.

javascript sapui5

5
推荐指数
1
解决办法
5369
查看次数

标签 统计

javascript ×1

sapui5 ×1