在Ember

时间:2016-07-10 23:00:28

标签: ember.js ember-data ember-cli

模型/ card.js

export default Model.extend({
  title: attr('string'),
  description: attr('string'),
  users: hasMany('user')
});

模型/ user.js的

export default Model.extend({
  email: attr('string'),
  name: attr('string'),
  cards: hasMany('card')
});

应用程序/路由/ cards.js

model() {
  let user = this.store.find('user', 1); // here user is defined

  user.get('cards').then((cards) => {
    console.log(cards); // here user.get('cards') is undefined
  });
}

我希望获得与cards相关联的所有关联user

回购链接:https://github.com/ghoshnirmalya/hub-client

1 个答案:

答案 0 :(得分:3)

.find()会返回一个承诺,所以你应该这样做:

this.store.find('user', 1)
  .then(user => user.get('cards'))
  .then(cards => console.log(cards));