[英]Apart from classNames & tagName, can other attributes be bound to an ember component?
I'm in the process of making the following block into a ember component: 我正在将以下块制作为余烬组件:
<div class="my-class" style="background-image: url('img.jpg')">
<!-- content -->
</div>
While I can define the main element's className, but it seems like there's no default way of adding other attributes in the main element of a component? 虽然我可以定义主要元素的className,但是似乎没有默认的方法可以在组件的主要元素中添加其他属性?
export default Ember.Component.extend({
classNames: ['my-class'],
someStyle: 'some style'
})
My current workaround wraps everything inside the component template, which outputs html like this: 我当前的解决方法是将所有内容包装在组件模板中,该模板将输出html,如下所示:
<div id="ember123" class="ember-view">
<div class="my-class" style="some style">
<!-- content -->
</div>
</div>
I'd like to know if there's a way to bind attributes to the main element of a component, so the output would be something like: 我想知道是否有一种方法可以将属性绑定到组件的主要元素,因此输出将类似于:
<div id="ember123" class="ember-view my-class" style="some style">
<!-- content -->
</div>
Yep, you can. 是的,可以。 You specify
attributeBindings
您指定
attributeBindings
export default Ember.Component.extend({
classNames: ['my-class'],
attributeBindings: ['someStyle:style'],
someStyle: 'some style'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.