user1025184 user1025184 - 6 months ago 65
HTML Question

OpenUI5: How to get the ID of html element inside view

I have a UIComponent with this view:

<mvc:View
controllerName="my.components.webmap.controller.Map"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:html="http://www.w3.org/1999/xhtml">
<html:div id='viewDiv' style='height:inherit'></html:div>
<Button id="helloWorld" text="Say Hello" press="onShowHello"/>
</mvc:View>


In the View controller, I can get the Button and its id from

this.getView().byId("helloWorld").sId


but I can't get the id of the Div using the byId() method.

this.getView().byId("viewDiv")
returns undefined.

How can i get the id of the div? I need the id of the div so I can append some additional 3rd party controls to it.

Answer

You can use View.createId() to convert your lokal id to a global one and use that with jQuery:

var viewDivId = this.getView().createId("viewDiv");
jQuery("#"+viewDivId).whatEver