I declared a model in Component.js of a UI5 application as below
init: function() {
sap.ui.core.UIComponent.prototype.init.apply(this);
var oModel1 = new sap.ui.model.json.JSONModel("model/mock.json");
sap.ui.getCore().setModel(oModel1, "oModelForSales");
},
but was not able to access the model in any of the onInit
methods inside controllers unless the model is set on view instead as below:
var oModel1 = new sap.ui.model.json.JSONModel("model/routes.json");
this.getView().setModel(oModel1);
The log for sap.ui.getCore().getModel("oModelForSales")
in controllers onInit
shows the model as undefined
but I was able to fetch it in onBeforeRendering
handler.
Why are core models, set in Component.js, not accessible in onInit
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…