mardi 21 avril 2015

Emberjs nested route index paramater

How do I get access to the params field from my index route that I created.

Here is my router.

export default Router.map(function() {
  this.resource('posts', function() {
    this.resource('posts.post', {path: ':id'}, function(){
      ...
      ...
      ...
    });
  });
});

When I go to /posts/1 and look at the ember inspector's view tree, I see for routes posts.post and posts.post.index both have {id: '1234'} for their model.

In the posts.post route, I can do the following:

export default Ember.Route.extend({
  model: function(params){
    console.log('params.id = ' + params.id);
  },
});

This prints to the console params.id = 1234.

However, when I run that same code in the posts.post.index route; params.id is undefined. As a matter of fact if I run JSON.stringify(params) it is empty.

How do I get access to the params form posts.post.index route. Ideally, I would like not to have to access the params from the posts.post route.

Any help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire