2
<span class="badge badge-inverse">{{kudosReceivedNum user.kudoReceiveds}}</span>

Ember.Handlebars.registerBoundHelper 'kudosReceivedNum', (kudos, options) ->
  kudosTotal = 0
  if kudos
    kudos.forEach (item) ->
      kudosTotal += item.get 'value'

    kudosTotal

申请路线:

newKudo = Sks.KudoReceived.createRecord value: kudoNum, comment: kudoComment
user.get('kudoReceiveds').pushObject(newKudo)

它仅在我进行刷新或从另一个视图转到时才有效。

4

1 回答 1

4

绑定助手实际上采用了一个额外的选项,即额外的依赖键。对于数组,您需要指定@each为依赖项。在我的脑海中,这看起来像:

Ember.Handlebars.registerBoundHelper 'kudosReceivedNum', ((kudos, options) ->
  kudosTotal = 0
  if kudos
    kudos.forEach (item) ->
      kudosTotal += item.get 'value'

    kudosTotal), '@each'
于 2013-04-29T16:37:14.080 回答