Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get params from nested routing in ember

This is the nested route that i have created in ember.

App.Router.map(function(){
 this.resource('makes', function(){
   this.resource('model', {path: ':division_id'}, function(){
     this.resource('zip', {path: ':model_id'});
   });
 });
 this.resource('spec', {path: '/makes/:division_id/:model_id/:zipcode'});
});

In the ziproute when i log the params this is the output i'm getting.

Object {model_id: "ILX"} 

But the url for zip route is like /makes/Acura/ILX. So i should be getting the both division_id and model_id.

I'm unable to get division_id in params.

Example app is done at : http://jsbin.com/jujene/36/edit

like image 351
Anbazhagan p Avatar asked Aug 05 '26 18:08

Anbazhagan p


1 Answers

Not sure if this is exactly what you're going for. In your route, you can get the parent model using Route.modelFor

App.ModelRoute = Ember.Route.extend({
     model: function(params){
       console.log('model params', params);
        return { id: params.division_id};
   },
});

Since Model route has access to the params, you can set it on your model that way. This way the Model Route sets up a model.

Then, on your zip route:

App.ZipRoute = Ember.Route.extend({

    model: function(params){
      var m = this.modelFor('model');
      console.log('division id', m.id);
      console.log('zip params', params);
      params.division_id = m.id;
     return params;
   }

});

See updated sample JSbin, which is a slightly cleaned up copy of yours.

like image 112
Mike Wilson Avatar answered Aug 08 '26 10:08

Mike Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!