cancel
Showing results for 
Search instead for 
Did you mean: 

How to get view elements from another view controller

SandipAgarwalla
Active Contributor
0 Kudos

Hi I have a IconTabBar defined with many steps in a view , lets say App.view.xml

Each step of the TabBar displays some content defined in their own respective view

How do I get access to the IcontabBar from another view lets say S1. Clicking on a tile in S1 view should take to the Step 2 of the IconTab Bar

On click of the tile, it should navigate to Step 2.

Thanks

Sandip

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor

is the information you are trying to access bindable? if yes, you can put them in model,which can be access across the views.

Former Member
0 Kudos

Hi,


Use "this.getView().byId()", which allows you to use the id you specified on the XML or HTML.


Regards,

Pradeep.

SandipAgarwalla
Active Contributor
0 Kudos

that may not work, as I need to access S0 View Elements from S2 View controller.    

Former Member
0 Kudos

In order to explain better this is the code.

  • This code works, when I am inside the controllor of the view that contains the list:

     var oList = this.getView().byId("list");    

     var items = oList.getItems();

  • This code doesn't work becasue I am trying to get the items from a list that is in a different view.

     var oList = sap.ui.getCore().byId("list");    


if you look into the View's byId-method, you can see that it prepends the views Id, it essentially calls sap.ui.getCore().byId(this.createId(id)).

This is so that you can instantiate a view several times without having duplicate IDs. In order to access the Controls from the outside, you either need the View so you can call view.byId(id), or you have to manually concatenate the view's id with the id like this: sap.ui.getCore().byId(viewId + "--" + id).

Follow this link for refrence.

sapui5 - sap.ui.getCore().byId() returns no element - Stack Overflow

Regards,

Pradeep

SandipAgarwalla
Active Contributor
0 Kudos

Thanks Pradeep

I am aware of getCore().byId() but was looking if there is a better way to do it.

Thanks

Sandip

Former Member
0 Kudos

Hi,

Other way i suggest is using global variable to access view elements