Skip to content Skip to sidebar Skip to footer

How To Get The Reference Id Of An Element In Another View - Ui5

How can I get the reference id of an element in another view? Like for example I have the following file structure (mvc) -view |-- View1.view.xml |-- View2.view.xml -controller |--

Solution 1:

You can use relative navigation. Do not use absolute Navigation, since that will not work anymore if you change like from local html to a FioriLaunchpad.

Commands you might want to look at:

Controller

Managed Object

Now you can navigate to the OwnerComponent, and there will be saved your target View, either as variable or as aggregation of your Element.

Solution 2:

Let's say the ID of the element in View1.view.xml is "idOfElement". you can access the reference of that element in another view(View2.controller.js) of the same application using the statement:

var elementID = sap.ui.getCore().byId("idOfElement");

Solution 3:

For example, I am trying to get an element which id is idAppControl in App.view.xml, and I want to access it in Master.controller.js

Here is my solution:

var ownerId = this.getView()._sOwnerId,
rootId = this.getOwnerComponent().getManifestEntry("sap.ui5").rootView.id,
id = "idAppControl",
realId = ownerId + "---" + rootId + "--idAppControl",   
element = sap.ui.getCore().byId(realId);

sOwnerId is a private property, I failed to find a better way to get it.

My manifest.json:

"sap.ui5":{"rootView":{"viewName":"xxx.view.App","type":"XML","id":"app"// what I get in rootId},}

Post a Comment for "How To Get The Reference Id Of An Element In Another View - Ui5"