Ember.js Embedded使用Ember进行了许多测试

Ember.js Embedded使用Ember进行了许多测试,ember.js,ember-data,Ember.js,Ember Data,我试图理解使用余烬的hasMany。特别是,我希望能够抓取特定的对象。我试着在上面抓取第一个对象,但是没有用。我也试过在每个物体上循环 及 重要代码: App.MyModel = DS.Model.extend({ name: DS.attr('string'), myOthers: DS.hasMany('App.MyOtherModel') }); DS.RESTAdapter.map('App.MyModel',{ myOthers: { embedded: 'always'

我试图理解使用余烬的hasMany。特别是,我希望能够抓取特定的对象。我试着在上面抓取第一个对象,但是没有用。我也试过在每个物体上循环

重要代码:

App.MyModel = DS.Model.extend({
  name: DS.attr('string'),
  myOthers: DS.hasMany('App.MyOtherModel')
});

DS.RESTAdapter.map('App.MyModel',{
  myOthers: { embedded: 'always' }
});

App.MyOtherModel = DS.Model.extend({
  name: DS.attr('string')
});

App.store.load(App.MyModel, {
  id: 2,
  name: "myModel",
  my_others: [
    { name: 'myOther1' },
    { name: 'myOther1' }
  ]
});

console.log(myModel.get("myOthers.firstObject.name"));
我试着这样做是为了我的测试,但我没有任何运气


我如何处理
具有多个
关系的对象,以便抓取特定对象并能够在其上循环?谢谢。

我发现你必须通过适配器,而不是商店

App.adapter = DS.RESTAdapter.create();
App.adapter.load(App.store, App.MyModel, {
  id: 2,
  name: "myModel",
  my_others: [
    { name: 'myOther1' },
    { name: 'myOther2' }
  ]
});