cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing elements of different views

Former Member
0 Kudos

Hi all,

I am having an issue accessing elements that are located in views different by the one of the control that I am using.

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

     var items = oList.getItems();

The error that I receive is:

Cannot read property 'getItems' of undefined



Thanks in advance for your help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Answers (2)

Answers (2)

Private_Member_15166
Active Contributor
0 Kudos

Alessandro Garofalo wrote:

Hi all,

I am having an issue accessing elements that are located in views different by the one of the control that I am using.

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

    

Just below it write console.log(oList);

here perhaps you will not get the data.

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

Dhananjay

Former Member
0 Kudos

Hi Alessandro,


Is it possible for you to give more information like sequence of calling both views?

As per my understanding your "list" is not initialized by the time you are calling in a different view.

Thanks.


Thanks.

Sarath.

Former Member
0 Kudos

Hi,

I am using classic fiori-like application with master and detail view.

The list is initialized in the master view, and I am trying to access its content from detail view.

Thanks

Alessandro