In my view class initialize function, _.bind(this.appendSection, this)
does not work, but _.bindAll(this, 'appendSection')
works. I am very confused...
Here is the code:
TemplateBuilder.Views.TemplateView = Backbone.View.extend({
el: $('div#evalTemplate'),
initialize: function(){
this.collection.on('reset', this.render, this);
//_.bind(this.appendSection, this);
_.bindAll(this, 'appendSection');
},
events: {
'click button#addSection': 'addSection'
},
render: function(){
this.collection.each(this.appendSection);
return this;
},
appendSection: function(section){
var view = new TemplateBuilder.Views.InstructionView({model: section});
this.$el.append(view.render().el);
},
addSection: function(){
var newSection = new TemplateBuilder.Models.Section();
this.collection.add(newSection);
this.appendSection(newSection);
},
});