在Ember中,不能在View's ObjectController上设置attributeBindings属性
Cannot set attributeBindings to property on View's ObjectController in Ember
我设法通过我的车把模板将attributeBinding设置为控制器上下文:
<li {{bindAttr class="view.controller.isSelected:active:"}}>
<a href="#" {{action "toggleSelected"}}>{{view.controller.title}}</a>
</li>
在每个组中这样调用:
<ul class="nav nav-tabs nav-stacked">
{{#each skill in controller}}
{{view App.SkillView}}
{{/each}}
</ul>
但是我发现EmberJS在每个视图周围添加div,这会导致我的CSS出现问题,所以我从模板中删除了li
标签,并在SkillView
中设置了tagName,并试图通过JS对象添加一个我想要的li DOM元素,但我使用的attributeBindings似乎不工作:
App.SkillView = Ember.View.extend({
templateName: 'skill',
tagName: 'li',
attributeBindings: ['controller.isSelected:active:']
});
App.SkillView = Ember.View.extend({
templateName: 'skill',
tagName: 'li',
attributeBindings: ['view.controller.isSelected:active:']
});
也:
App.SkillView = Ember.View.extend({
templateName: 'skill',
tagName: 'li',
attributeBindings: ['isSelected:active:']
});
如何在视图绑定字符串的上下文中从视图中引用控制器?我在车把模板上做什么,我在视图代码中没有做什么?
原来我应该使用classNameBindings而不是attributeBindings。
App.SkillView = Ember.View.extend({
templateName: 'skill',
tagName: 'li',
classNameBindings: ['controller.isSelected:active:']
});
相关文章:
- 没有找到相关文章