我有一份任务清单。每个任务旁边都有一个子弹列表(子项)。 子弹可以切换。
我有2条路线只显示已完成和活动的任务。 显示任务本身和在路线之间切换工作总是很好,子弹也会显示。
问题:
当我删除DayCompletedRoute& DayActiveRoute再次渲染子弹。
为什么不使用多条路线?
App.Router.map(function () {
this.resource('days', {path: "/"}, function () {
this.resource('day', {path: "/days/:day_id"}, function () {
this.route('active');
this.route('completed');
})
this.route('new', {path: "/days/new"});
});
});
// ROUTES
App.DaysRoute = Ember.Route.extend({
model: function () {
return this.store.find('day');
}
});
App.DayRoute = Ember.Route.extend({
model: function (day) {
return this.store.find('day', day.day_id);
}
});
App.DayIndexRoute = Ember.Route.extend({
model: function () {
return this.modelFor('day');
}
});
App.DayCompletedRoute = Ember.Route.extend({
model: function(){
return this.modelFor('day').get('tasks').then(function(tasks){
return tasks.filterBy('isCompleted', true);
});
}
});
App.DayActiveRoute = Ember.Route.extend({
model: function() {
return this.modelFor('day').get('tasks').then(function(tasks){
return tasks.rejectBy('isCompleted', true);
});
},
renderTemplate: function(controller) {
this.render('day/completed', {controller: controller});
}
});
模板摘要:
<script type="text/x-handlebars" data-template-name="application">
// navigation here
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="days/new">...</script>
<script type="text/x-handlebars" data-template-name="days">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="day">
{{input type="text" placeholder="What needs to be done?" value=newTitle action="createTask"}}
{{outlet}}
{{#link-to "day.index" activeClass="selected"}}All{{/link-to}}
{{#link-to "day.completed" activeClass="selected"}}Completed{{/link-to}}
{{#link-to "day.active" activeClass="selected"}}Active{{/link-to}}
</script>
<script type="text/x-handlebars" data-template-name="day/index">
{{#each task in this.tasks}}
{{task.title}}
{{#each item in task.sortedItems}}
{{input type="checkbox" checked=item.filled}}
{{/each}}
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name="day/completed">
{{#each itemController="task"}}
{{title}}
{{#each item in sortedItems}}
{{input type="checkbox" checked=item.filled}}
{{/each}}
{{/each}}
</script>