I am learning a bit of Ember and trying to implement with some of our data. I have the following which is esentially a master - detail and need the detail to make a JSON call that would be implemented in the model hook:
<script type='text/x-handlebars' data-template-name='inventoryperiods'>
before loop
{{#each}}
<div>{{#link-to "ipshow" this}}{{id}}{{/link-to}}</div>
{{/each}}
</script>
...
Inv.Router.map(function() {
this.resource('inventoryperiods', {path: '/'});
this.route('ipshow', {path: '/ip/:ip_id'});
});
Inv.InventoryperiodsRoute = Ember.Route.extend({
model: function() {
return [{id:1, name:"Frank"}, {id:2, name:"Allan"}];
}
});
Inv.IpshowRoute = Ember.Route.extend({
model: function(params) {
alert('within period detail model' + params.ip_id);
var my_name="Jonathan " + params.ip_id;
return {name:my_name};
}
});
and when I go to '/' - I get the list but clicking on 1 gives me Frank when I think that the model hook should be called and give me 'Jonathan 1'. I get the idea that I'm passing this but it seems like there should be a way to tell the route that there is more detail that I need than exists in that object.
In jsbin: http://jsbin.com/qazoz/3/edit?html,output
and to see that Jonathan 1 comes out if I go to that directly, go to: http://jsbin.com/qazoz/3#/ip/1
I see this discussion: Why isn't my ember.js route model being called?
Ember has the assumption, that you do not necessarily make a call to the model hook, if you use {{linkTo}}. In your places template you use {{#linkTo 'place' place}} {{place.name}} {{/linkTo}}. You are passing a place object to your route. Ember assumes that this is the same object, that you would get when executing your model hook. So from Embers View there is no need to call the model hook. So if you want to perform retrieval logic even when you use linkTo, use the setupController hook.
but the adding the setupController doesn't seem to change this behavior.