简体   繁体   English

在HTML5中使用自定义data- *属性 <template> 标签

[英]Using custom data-* attributes inside HTML5 <template> tag

I'm building a menu with a dom-repeat template like this: 我正在建立一个带有dom-repeat模板的菜单,如下所示:

        <template is="dom-repeat" items="{{appletsMenu}}">
              <a data-route="{{item.dataRoute}}" href="{{item.href}}">
                <iron-icon icon="{{item.icon}}" src="{{item.iconSrc}}" ></iron-icon>
                <span>{{item.name}}</span>
              </a>
        </template>

The data-route attribute is not filled though in the generated DOM: 虽然在生成的DOM中未填充data-route属性:

<a href="...">...</a>
<a href="...">...</a>

It seems that the template only renders "normal" attributes like href . 似乎该模板仅呈现“普通”属性,例如href Am I'm missing something? 我在想什么吗? Thanks. 谢谢。

To bind to an attribute, use $= rather than =. 要绑定到属性,请使用$ =而不是=。 This results in a call to: 这导致调用:

element.setAttribute(attr, value);

As opposed to: 相对于:

element.property = value;

(source) (资源)

So in your case: 因此,在您的情况下:

<a data-route$="{{item.dataRoute}}" href="{{item.href}}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM