すべてが期待どおりに機能するアプリケーションがありますがlink-to
、子ルートに直接移動すると、モデル データが読み込まれないようです。私の子(タイプ)ルートthis.modelFor
では、モデルフックで使用しています。これはビンですhttp://emberjs.jsbin.com/oSApiSeh/7#/types/secondaryそこを直接ナビゲートしても色は表示されませんが、セカンダリをクリックすると機能します。
その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'}
];
私のテンプレート:
<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>