只是想知道为什么会这样:
window.NewListView = Backbone.View.extend({
template: _.template('<a href="/list" class="button new-list">Create New List</a>'),
render: function(){
$(this.el).html(this.template());
return this;
}
});
window.List = new (Backbone.Router.extend({
routes: { "": "index" },
initialize: function(){
this.newListView = new NewListView();
},
start: function(){
Backbone.history.start();
},
index: function(){
$('.lists').append(this.newListView.render().el);
}
}));
$(function(){ List.start(); })
这不会:
window.NewListView = Backbone.View.extend({
template: _.template('<a href="/list" class="button new-list">Create New List</a>'),
render: function(){
$(this.el).html(this.template());
return this;
}
});
window.List = new (Backbone.Router.extend({
routes: { "": "index" },
initialize: function(){
this.newListView = new NewListView();
$('.lists').append(this.newListView.render().el);
},
start: function(){
Backbone.history.start();
},
index: function(){
}
}));
$(function(){ List.start(); })
区别只是移动
$('.lists').append(this.newListView.render().el);
在路由器的 initialize() 和 index() 之间。