padibro
padibro

Reputation: 1382

How to retrieve view outside the controller

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.

Upvotes: 5

Views: 26184

Answers (3)

user7017477
user7017477

Reputation: 1

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.

Upvotes: 0

padibro
padibro

Reputation: 1382

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");

Upvotes: 2

Tim Gerlach
Tim Gerlach

Reputation: 3390

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.

Upvotes: 3

Related Questions