我现在正在研究ember.js教程.我在"添加子路线"一章时遇到了问题.我的待办事项列表未显示."todos"模板输出很好,但"todos/index"模板根本不起作用.控制台不显示任何错误.我想这是一些本地问题或一些bug.也许有人已经遇到过类似的问题.这个问题可能是什么原因?我怎么解决呢?谢谢.
HTML:
Ember.js • TodoMVC
JS:
window.Todos = Ember.Application.create(); Todos.ApplicationAdapter = DS.FixtureAdapter.extend(); Todos.Router.reopen({ rootURL: '/one/' }); Todos.Router.map(function () { this.resource('todos', { path: '/' }); }); Todos.TodosRoute = Ember.Route.extend({ model: function () { return this.store.find('todo'); } }); Todos.TodosIndexRoute = Ember.Route.extend({ model: function () { return this.modelFor('todos'); } }); Todos.Todo = DS.Model.extend({ title:DS.attr('string'), isCompleted:DS.attr('boolean') }); Todos.Todo.FIXTURES = [ { id: 1, title: 'Learn Ember.js', isCompleted: true }, { id: 2, title: '...', isCompleted: false }, { id: 3, title: 'Profit!', isCompleted: false } ]; Todos.TodosController = Ember.ArrayController.extend({ actions: { createTodo: function () { // Get the todo title set by the "New Todo" text field var title = this.get('newTitle'); if (!title.trim()) { return; } // Create the new Todo model var todo = this.store.createRecord('todo', { title: title, isCompleted: false }); // Clear the "New Todo" text field this.set('newTitle', ''); // Save the new model todo.save(); } }, remaining: function () { return this.filterBy('isCompleted', false).get('length'); }.property('@each.isCompleted'), inflection: function () { var remaining = this.get('remaining'); return remaining === 1 ? 'item' : 'items'; }.property('remaining'), }); Todos.TodoController = Ember.ObjectController.extend({ actions:{ editTodo: function () { this.set('isEditing', true); }, acceptChanges: function () { this.set('isEditing', false); if (Ember.isEmpty(this.get('model.title'))) { this.send('removeTodo'); } else { this.get('model').save(); } }, removeTodo: function () { var todo = this.get('model'); todo.deleteRecord(); todo.save(); }, }, isEditing: false, isCompleted: function(key, value){ var model = this.get('model'); if (value === undefined) { // property being used as a getter return model.get('isCompleted'); } else { // property being used as a setter model.set('isCompleted', value); model.save(); return value; } }.property('model.isCompleted') });
Kingpin2k.. 5
从技术上讲,这不是一个错误,团队认为如果你不能在路由器中更深入地进行索引路由没有意义(这是因为todos
路由和模板将呈现,所以没有真正需要索引路径.话虽这么说,如果你真的想要它,添加一个匿名函数,你就会得到它.
Todos.Router.map(function () { this.resource('todos', { path: '/' },function () {}); });
https://github.com/emberjs/ember.js/issues/3995
从技术上讲,这不是一个错误,团队认为如果你不能在路由器中更深入地进行索引路由没有意义(这是因为todos
路由和模板将呈现,所以没有真正需要索引路径.话虽这么说,如果你真的想要它,添加一个匿名函数,你就会得到它.
Todos.Router.map(function () { this.resource('todos', { path: '/' },function () {}); });
https://github.com/emberjs/ember.js/issues/3995