vendredi 3 juillet 2015

Ember Data - Handle API error responses for a hasmany relationship that is accessed through a template

I have a model that is being accessed through a hasmany relationship from a handlebars template

models/post.js

export default DS.Model.extend({
    comments: DS.hasMany('comment', {async: true}),
});

template/post.hbs

{{#each comment in post.comments}}

I'm using the REST adapter and need to handle success and failure responses for the GET /posts/:id/comments that is being done from the handlebars template helper.

If this was being done in a controller/route, I could just do something like:

this.store.find('post', post_id)
  .then(function(post) {
     post.get('comments);
  }, function(errors) {
     // handle errors
  });

Where do I do the equivalent when accessed through the template? Any help or words or wisdom are very much appreciated!




Aucun commentaire:

Enregistrer un commentaire