I am in the process of creating a Backbone view using an Underscore template. I am utilizing the setElement function to replace the view el with the template html, as stated in the function's declaration that it should "...move the view's delegated events from the old element to the new one". However, for some reason, this functionality does not seem to be working correctly. Can anyone provide insight into why this is not functioning as described in the Backbone declaration?
Here is an example illustrating the issue (relevant sections of the view):
initialize: function(args) {
_.extend(this, args);
this.listenTo(this.model, 'change', this.render);
},
events: {
'click .active-area': '_test'
},
_test: function() {
// The event doesn't trigger after "setElement" is called.
this.model.set('color', 'green');
},
render: function() {
// The "click" listener no longer works after this point.
this.setElement(this.template(this.model.toJSON());
return this;
}