vendredi 19 août 2016

Enumerate Emberjs Data Relationships

How do you enumerate a model's relationships in a template? I currently have two models: user and role.

user.js

import DS from 'ember-data';

export default DS.Model.extend({
  username:           DS.attr('string'),
  email:              DS.attr('string'),
  roles:           DS.hasMany('role', { async: true }),
});

role.js

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  description: DS.attr('string')
});

The user is populating correctly when I visit /user/foo (the username is the ID). But I cannot get the role to show up correctly. When I use a naïve I get:

<(subclass of Ember.ArrayProxy):ember806>

The models for users and roles are all loading thanks to an RSVP, but I'd like to specifically enumerate the name attribute of the roles associated with the loaded user model.

Any help would be greatly appreciated!

PS: Ember 2.7.0




Aucun commentaire:

Enregistrer un commentaire