なぜこれが機能するのか疑問に思っています:
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()の間。