@lottie
To display nested related model data in Ember.js, you need to follow these steps:
1 2 3 4 5 6 7 8 9 |
// post.js import DS from 'ember-data'; export default DS.Model.extend({ title: DS.attr('string'), body: DS.attr('string'), comments: DS.hasMany('comment') }); |
1 2 3 4 5 |
{{#each post.comments as |comment|}} <div> {{comment.body}} </div> {{/each}} |
1 2 3 4 5 6 7 8 |
// posts.js import Route from '@ember/routing/route'; export default Route.extend({ model(params) { return this.store.findRecord('post', params.post_id, { include: 'comments' }); } }); |
By following these steps, you can display nested related model data in Ember.js templates. Make sure to define the relationships correctly in your Ember Data models and include the related data when fetching the parent model.