UI5:如何访问在视图中定义的 html 元素?

use*_*184 3 html javascript sapui5

我有一个带有此视图的 UIComponent:

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

在视图控制器中,我可以从

this.getView().byId("helloWorld").sId
Run Code Online (Sandbox Code Playgroud)

但我无法使用该byId()方法获取 div 的 ID 。

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

如何获取 div 的 ID 以访问该元素?我需要 div 的 ID,所以我可以向它附加一些额外的 3rd 方控件。

sch*_*del 5

您可以使用createId 将您的本地 ID 转换为全局 ID,并将其用于getElementById

// After rendering
var divId = this.createId("myDiv"); // this == controller instance
document.getElementById(divId).whatEver
Run Code Online (Sandbox Code Playgroud)