3
codeschool.com主干课程水平7有以下代码下方,并指出,整个事情可以用下面的jQueryBackbone初始路由如何在文档准备好后调用?
$(function(){ TodoApp.start() })
它将调用Backbone.history.start
拉开序幕。但是如何调用Backbone.history.start
最终导致index
被调用,因此调用fetch
来填充模型集合todoList
。
var TodoApp = new (Backbone.Router.extend({
routes: { "": "index", "todos/:id": "show" },
initialize: function() {
this.todoList = new TodoList();
this.todosView = new TodoListView({collection: this.todoList});
$('#app').append(this.todosView.el);
},
start: function(){
Backbone.history.start({pushState: true});
},
index: function(){
this.todoList.fetch();
},
show: function(id){
this.todoList.focusOnTodoItem(id);
}
}));