What is the replacement for metadataLoaded in JSON model?

本小妞迷上赌 提交于 2019-12-25 15:31:09

问题


In sap.ui.model.odata.v2.ODataModel, there is a metadataLoaded method which I can use it like this:

this.getModel().metadataLoaded().then( function() {
    var sObjectPath = this.getModel().createKey("/", {
        ID :  sObjectId
    });
    this._bindView("/" + sObjectPath);
}.bind(this));

in JSONModel, it seems no corresponding method since there is no metadata in JSONModel, so is there any other work around?

I tried attachRequestCompleted not working.

function bindview() {
    that._bindView(sObjectId);
}
this.getModel().attachRequestCompleted(bindview);

回答1:


As you rightly said, there is no metadata. But for Json model why do you want to wait for any event? You can directly bind the view.




回答2:


attachRequestCompleted only fires once when model is loaded, So I fix this problem in this way:

jsonModelLoaded: false,

_onObjectMatched : function (oEvent) {
    if(this.jsonModelLoaded) {
        this._bindView(sObjectId);
    }

    function bindview() {
        that.jsonModelLoaded = true;
        that._bindView(sObjectId);
    }
    this.getModel().attachRequestCompleted(bindview);
}

another not documented solution is using this.getModel().attachRequestCompleted().pSequentialImportCo‌​mpleted.then()

Related question here: Why metadataLoaded can be fired multiple times?



来源:https://stackoverflow.com/questions/43772916/what-is-the-replacement-for-metadataloaded-in-json-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!