Accessing Core Model from Controller Not Working [duplicate]

人盡茶涼 提交于 2020-01-03 05:43:10

问题


I have added a named model in Component.js. I can access model with its name from any view but I want to access this model from one of the controllers which is not working for me.

sap.ui.core.getModel("modelName") is not working and sap.ui.getCore().getModel("modelName") is also not working.

How to refer its containing Component and a named model from a controller?


回答1:


If the model was registered using the manifest path sap.ui5->models it seems to be available in the controllers only by

  this.getOwnerComponent().getModel(modelName);

I have experienced this especially for the i18n model.




回答2:


Please use this.getView().getModel(name) in your controller. To address the issue that models created in/from the Component are not yet ready in onInit I added a getModel method in my base controller:

getModel : function(name) {
    return this.getView().getModel(name) || this.getOwnerComponent().getModel(name);
}


来源:https://stackoverflow.com/questions/35100650/accessing-core-model-from-controller-not-working

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