Ember.js 每个与第一个对象的余烬数据差异

Ember.js 每个与第一个对象的余烬数据差异,ember.js,ember-data,Ember.js,Ember Data,也许我误解了每个人 为什么@each选择数组是空的 this.get('taggings.@each.selection').toArray() [] 但是第一个对象出现了: this.get('taggings.firstObject.selection.id') "528d0f2b6dc8270d2f0002df" 同样,我可以这样做: this.get('taggings').toArray()[0].get('selection.id') "528d0f2b6dc8270d2f000

也许我误解了每个人

为什么@each选择数组是空的

this.get('taggings.@each.selection').toArray()
[]
但是第一个对象出现了:

this.get('taggings.firstObject.selection.id')
"528d0f2b6dc8270d2f0002df"
同样,我可以这样做:

this.get('taggings').toArray()[0].get('selection.id')
"528d0f2b6dc8270d2f0002df"
但我宁愿写更简洁的“taggings.@each.selection”

以下是更多的上下文:

App.Folder = DS.Model.extend(App.Auditable, {
  //....
  taggings: DS.hasMany('tagging', {async: true}),
  //...
  selections: function() {
    return this.get('taggings.@each.selection');
  }.property('taggings.@each'),

@每个都用于表示依赖关系(在属性方法中),而不是作为getter

不过,有一些很好的方法可以映射结果

this.get('taggings').map(function(tagging){return tagging.get('selection')});
甚至更小

this.get('taggings').getEach('selection');