Ember: access has many relationship array

Ember: access has many relationship array

我有,说:

App.Post = DS.Model.extend({
  comments: DS.hasMany('App.Comment')
});

App.Comment = DS.Model.extend({
  post: DS.belongsTo('App.Post')
});

在某些代码中,我检索了 post 并且我想循环处理它的注释:

var comment;
var post = store.all('post').content[0];
for (var i=0; i<post.get('comments').length; i++) { // length attributes exists
  // comment is undefined
  comment = post.get('comments')[i]; // also tried post.get('comments').get(i);
}

我该怎么做?

诀窍是一个 toArray() 方法,感谢这个 post,虽然我从未在文档中找到它:

var comment;
var post = store.all('post').content[0];
var comments = post.get('comments').toArray();
for (var i=0; i<comments.length; i++) { // length attributes exists
  comment = comments[i];
}