XML 视图元素中的数据属性 [英] Data attribute in XML View elements

查看:47
本文介绍了XML 视图元素中的数据属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 XML 视图中的元素添加数据属性,如下所示:

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>

但找不到方法,除非我通过 Controller 分配它们.

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

尝试使用 CustomData 命名空间,但它只添加数据,没有向 DOM 元素添加 HTML 属性.

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

有什么想法吗?

谢谢!

推荐答案

您只能使用标准控件属性来影响写入 DOM 的属性.如果标准属性没有为您提供设置正确 HTML 属性的方法,而您仍希望在 DOM 中获得自己的 HTML 属性,则需要对控件进行子类化并编写自己的渲染器.当您编写自己的渲染器时,您可以完全控制写入 DOM 的内容.

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.

您可以在第 34 步 SAPUI5 演练.

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

这篇关于XML 视图元素中的数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆