Data attribute in XML View elements

此生再无相见时 提交于 2021-01-27 19:22:31

问题


I'm trying to add data attributes to elements in a XML View as below:

<core:FragmentDefinition
    xmlns="sap.m"
    <VBox data-help-id="Some.String.Here">
        ...
    </VBox>
</core:FragmentDefinition>

but couldn't find how to do it, unless I assign them via Controller.

Tried using CustomData namespace, but it only adds data, without adding the HTML attribute to the DOM element.

Any idea?

Thanks!


回答1:


You can only influence the attributes written to the DOM using the standard control properties. If the standard properties don't provide you with a way to set the right HTML attibutes, and you still want to get your own HTML attributes in the DOM, you'll need to subclass the control and write your own renderer. When you write your own renderer, you have full control over what's written to the DOM.

You can find more information on writing custom controls in Step 34 of the SAPUI5 Walkthrough.




回答2:


actually you can do something very close and associate data to your xmlView. This is available for xml views and more. Check this url for more details: Custom Data - Attaching Data Objects to Controls

What you would need to do is add a custom namespace to your xmlView:

xmlns:dataHelp="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"

...

<core:FragmentDefinition
    xmlns="sap.m"
    <VBox dataHelp:id="Some.String.Here" id="myBox"
        ...
    </VBox>
</core:FragmentDefinition>

you are then able to set and consume this attribute in your binding and javascript/controller/event handler:

sap.ui.getCore().byId("myBox").data("id") // = Some.String.Here


来源:https://stackoverflow.com/questions/38055883/data-attribute-in-xml-view-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!