在{{#linkTo}}帮助器< a>上设置自定义数据属性标签 [英] Set custom data- attributes on {{#linkTo}} helper <a> tag
问题描述
如何在 {{linkTo}}
帮助器的标签上设置自定义数据属性?
How can I set custom data- attributes on the {{#linkTo}}
helper's a tag?
所以要使用这个:
{{link tofoodata-toggle =dropdown}} foo {{/ linkTo}}
,结果应如下所示:
< a id =ember323class =ember-view activedata-toggle =dropdownhref =#/ foo / 123> foo< / a>
但它看起来像
< a id =ember323class =ember-查看活动href =#/ foo / 123> foo< / a>
我该怎么做? >
How can I do this?
推荐答案
您可以这样做的一种方法是将您的 Ember.LinkView
扩展为意识到新属性:
A way you could do this is to extend your Ember.LinkView
to be aware of the new attribute:
Ember.LinkView.reopen({
attributeBindings: ['data-toggle']
});
然后,您可以在 {{link-to} }
helper:
And then you can use it in your {{#link-to}}
helper:
{{#link-to 'foo' data-toggle="dropdown"}}Foo{{/link-to}}
这将导致:
<a id="ember262" class="ember-view active" href="#/foo" data-toggle="dropdown">Foo</a>
由于 attributeBindings
是一个数组,你可以在您可能需要的地方放置多个属性:
And since attributeBindings
is an array your can put multiple attributes there that you might need:
attributeBindings: ['data-toggle', 'foo', 'bar']
希望有帮助。
这篇关于在{{#linkTo}}帮助器< a>上设置自定义数据属性标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!