我应该如何更改以下代码以按预期工作,所以如果我完成了一个待办事项,则不会改变其他待办事项的完整性?
itemController="todo" 声称将每个项目包装在自己的控制器中,但没有这样做。
索引.html
<script type="text/x-handlebars" id="todos">
<ul>
{{#each controller itemController="todo"}}
<li>{{#link-to 'todo' this}}{{job}} -- {{#if isCompleted}}Completed{{else}}Incomplete{{/if}}{{/link-to}}</li>
{{/each}}
</ul>
{{outlet}}
</script>
<script type="text/x-handlebars" id="todo">
<p>Job: {{job}} -- {{#if isCompleted}}Completed{{else}}Incomplete{{/if}}</p>
<button {{action 'complete' controller}}>Complete</button>
</script>
应用程序.js
App = Ember.Application.create();
App.Router.map(function() {
this.resource('todos', function() {
this.resource('todo', { path: ':todo_id' })
});
});
App.IndexRoute = Ember.Route.extend({
redirect: function() { this.transitionTo('todos'); }
});
App.TodosRoute = Ember.Route.extend({
model: function() {
return todos;
}
});
App.TodoRoute = Ember.Route.extend({
model: function(params) {
return todos.findBy('id', params.todos_id);
}
});
App.TodosController = Ember.ArrayController.extend({
});
App.TodoController = Ember.ObjectController.extend({
isCompleted: false,
actions: {
complete: function() {
this.set('isCompleted',true);
}
}
});
var todos = [{id: '1', job: 'running'}, {id: '2', job: 'swimming'}, {id: '3', job: 'study'}];