Reputation:
I have a master-details application in SAPUI5 (The application has been made by WebIde template applications).
The view inside of the App
is set to busy and I need to unbusy the view in child view. Thus I need to access the parent view.
So in Master.controller.js
I need to access the owner component view. All controllers inherited from BasicController and have setModel
and getModel
functions. While inside of the App.controller.js
there is a line like this:
this.setModel(oViewModel, "appView");
I can not access this view model in master controller by:
this.getModel("appView");
It returns undefined
. There is command that I can get owner component:
this.getOwnerComponent()
But how can I get view of the owner component or its OViewModel
?
Upvotes: 2
Views: 4525
Reputation: 5713
See your rootView in your manifest.json which should be your App controller. https://sapui5.hana.ondemand.com/#docs/guide/be0cf40f61184b358b5faedaec98b2da.html
Put the following code in your base controller.
this.getOwnerComponent().getAggregation("rootControl").getModel("appView")
I tried the code in Worklist.controller.js which is part of a UI5 demo project at https://sapui5.hana.ondemand.com/test-resources/sap/m/demokit/tutorial/worklist/07/webapp/test/mockServer.html and it is working OK.
Thank you!
Upvotes: 2
Reputation: 1026
You want to access a model that is defined only in DetailView from the Masterview controller?
First get a grip on the DetailView, then you can access the model there.
sap.ui.getCore().byId("IdOfDetailView").getModel("appView");
Upvotes: 2
Reputation: 361
You should be able to access your models anywhere as long as you used getModel()
with the correct name inside the parenthesis. Do you have a model defined in your Component.js
, or wherever SAP suggests defining them, named "appView"?
Upvotes: 0