How to retrieve View outside the controller - Openui5

荒凉一梦 提交于 2019-12-19 04:05:58

问题


If I use this.getView() inside the controller of a view I can retrieve it without problems. How can I retrieve the view if I am outside the controller (e. g. in controller of another view)?

I try sap.ui.core.Core().byId("<name of view>") but it returns undefined.


回答1:


You can instantiate another view using:

var view = sap.ui.jsview("<name of view>");

If you´re using different view types you can choose the necessary function from here.

To avoid multiple instantiation you could do something like this:

var view = sap.ui.getCore().byId("id");

if (view === undefined) {
    view = sap.ui.jsview("id", "<name of view>");
}

See this for more details regarding view definition/instantiation and IDs.




回答2:


When I create a view i set a id

var theView=sap.ui.xmlview("OperationDetail, "<name of view>");

then i retrieve it by id

var theView = sap.ui.core.Core().byId("OperationDetail");
var myPage=theView.byId("pageOperation");



回答3:


varRequired = sap.ui.getCore().byId("<name of view>");

this keyword refers to only the particular controller where as sap.ui.getCore() refers to the project views.



来源:https://stackoverflow.com/questions/24267621/how-to-retrieve-view-outside-the-controller-openui5

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