问题
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().pSequentialImportCompleted.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