3

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

Anbazhagan p
  • 943
  • 1
  • 14
  • 27

1 Answers1

1

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.

Mike Wilson
  • 692
  • 6
  • 12
  • zip Cannot read property 'set' of undefined TypeError: Cannot read property 'set' of undefined – Anbazhagan p Oct 29 '14 at 16:21
  • Where are you getting that? I didn't have time to cleanup the JSbin all the way, but I don't get that error if I start from the beginning and click through the links. Either way, this technique above is how you get access to the parent model. – Mike Wilson Oct 29 '14 at 16:29
  • still when i return params i get only model id, but in console log i can see division id also . how do i get access to m variable in views – Anbazhagan p Oct 30 '14 at 09:55
  • In your Zip route, get access to the Model model (and therefore the division id), then you can add that property to your Zip model. – Mike Wilson Oct 30 '14 at 16:14
  • I updated the JSbin to show how you would set the division id on the zip route, and how to data bind to it. – Mike Wilson Oct 30 '14 at 16:20