1

我的控制器中有一个值,而不是我想用来绑定到动态类的值。

isSelected: (->
    this.get('selectedConference') == '1A'
  ).property('selectedConference')

但不是 1A 我希望它与每个块中循环的值进行比较。

  {{each conference in controller.reverseConferences}}
    <li>
      <a>
        {{isSelected}}

我如何将 {{this}} 传递给 isSelected?

4

2 回答 2

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
于 2013-04-04T02:03:57.960 回答
0

在这种情况下,您需要使用会议控制器上itemControllereach助手和属性。needs这是一个可以帮助您的 jsbin:http: //jsbin.com/atomuy/3/

允许将itemController您的会议模型包装到控制器中并isSelected在模板中创建您需要的属性。每次点击会议,select都会触发动作,通过的会议会被设置为selected会议ConferencesController。每个ConferenceController观察选定的会议。isSelected如果它恰好与传递的属性相同,则属性将发生变化。数据绑定会为您更新所有内容。

希望能帮助到你

于 2013-04-03T04:29:53.410 回答