Ember.js 将新属性添加到余烬对象时触发观察者

Ember.js 将新属性添加到余烬对象时触发观察者,ember.js,coffeescript,Ember.js,Coffeescript,我想激发一个观察者,当另一个余烬对象有一个新的属性集时,该观察者将为属性设置一个值。到目前为止,我是这样得到的: relationTotalCountObserver: Ember.observer('item.relationships.attachments', -> totalCount = @get 'item.relationships.attachments.totalCount' if totalCount isnt undefined @set 'rel

我想激发一个观察者,当另一个余烬对象有一个新的属性集时,该观察者将为属性设置一个值。到目前为止,我是这样得到的:

  relationTotalCountObserver: Ember.observer('item.relationships.attachments', ->
  totalCount = @get 'item.relationships.attachments.totalCount'
  if totalCount isnt undefined
    @set 'relationTotalCount', totalCount
  ).on 'init'

该项目之前没有任何totalCount属性,最终将使用合并补丁添加该项目,我需要以某种方式检测该添加。

为什么不为totalCount添加oberserve,如Ember.observer('item.relationships.attachments.totalCount'当在'init'上安装observer时,item.relationships.attachments.totalCount属性尚不存在,它将在以后添加,并且observer显然不会触发,因为它没有观察到任何内容。这会起作用吗?我使用了notifyPropertyChange否,抱歉。observer已添加到'item.r'中relationships.attachments属性而不是'item.relationships.attachments.totalCount'属性。添加该属性似乎不会触发observer.Ember.observer('item.relationships.attachments.totalCount')应该可以正常工作。您使用的是什么版本的Ember?