I have an application that when following a link-to
everything works as expected, but when navigating directly to a child route my model data doesn't seem to load. In my child (types) route I am using this.modelFor
in my model hook. Here is a bin http://emberjs.jsbin.com/oSApiSeh/7#/types/secondary navigating there directly doesn't show the colors, but if you click secondary it works.
Here is the source of that jsbin:
// ... groupBy definition omitted
App = Ember.Application.create();
App.Router.map(function() {
this.resource('colors', { path: '/' }, function() {
this.resource('types', { path: 'types/:type_group' }, function() {});
});
});
App.ColorsRoute = Ember.Route.extend({
model: function() {
return App.Color.find();
}
});
App.TypesRoute = Ember.Route.extend({
model: function(params) {
return this.modelFor('colors').filterBy('type', params.type_group);
}
});
App.ColorsController = Ember.ArrayController.extend({
grouped: _groupBy('type')
});
App.TypesController = Ember.ArrayController.extend({});
App.Color = Ember.Model.extend({
'color':Ember.attr('string'),
'type': Ember.attr('string')
});
App.Color.adapter = Ember.FixtureAdapter.create();
App.Color.FIXTURES = [
{ color:'red', type: 'primary'},
{ color:'green', type: 'primary'},
{ color: 'yellow', type: 'secondary'},
{ color: 'orange', type: 'secondary'},
{ color: 'blue', type: 'primary'}
];
My templates:
<script type="text/x-handlebars">
<h2> Welcome to Ember.js</h2>
{{outlet}}
I am wanting a route to .../primary that has red, green, and blue as its model and a route to .../secondary that has yellow and orange in its model
</script>
<script type="text/x-handlebars" data-template-name="colors">
<ul>
{{#each grouped}}
<li>{{#link-to 'types' group}}{{group}} ({{content.length}}){{/link-to}}</li>
{{/each}}
</ul>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="colors/index">
all colors
</script>
<script type="text/x-handlebars" data-template-name="types">
Types
<ul>
{{#each item in controller}}
<li>{{item.color}} </li>
{{/each}}
</ul>
</script>