我的控制器中有一个值,而不是我想用来绑定动态类。
isSelected: (->
this.get('selectedConference') == '1A'
).property('selectedConference')
但是我希望它将它与每个块中循环的值进行比较而不是1A。
{{each conference in controller.reverseConferences}}
<li>
<a>
{{isSelected}}
我如何将{{this}}传递给isSelected?
答案 0 :(得分:0)
在这种情况下,您需要在会议控制器上使用itemController
帮助程序的each
和needs
属性。这是一个可以帮助你的jsbin:http://jsbin.com/atomuy/3/。
itemController
允许将会议模型包装到Controller中,并创建模板中需要的isSelected
属性。每次点击会议时,都会触发select
操作,会议通过的selected
会议将设置为ConferencesController
。每ConferenceController
次观察所选会议。如果isSelected
属性恰好与传递的属性相同,则会发生变化。数据绑定可以为您更新所有内容。
希望有所帮助
答案 1 :(得分:0)
这里的解决方案是创建一个视图并在那个
中进行绑定App.TeamsConferencesView = Ember.View.extend
templateName: "teams/conferences"
selectedBinding: 'controller.selectedConference'
loadingBinding: 'controller.loadingData'
ConferenceItemView: Ember.View.extend
tagName: 'li'
classNameBindings: 'isActive:active'.w()
isActive: (->
this.get('content') == this.get('parentView.selected');
).property('item', 'parentView.selected').cacheable()
现在,当我在控制器中更新selectedConference时,它将绑定到我的视图并激活相应的项目。
我的会徽模板看起来像这样
each conference in controller.reverseConferences
view view.ConferenceItemView contentBinding="conference"
linkTo teams.conferences conference
conference