I\'m using Backbone.js and sometimes the views events do not get bound correctly.
I can check the event binding situation with $(viewselector).data()
in
My approach in these scenarios is to add delegateEvents()
in render of each view that has an event, like the following:
$(this.el).empty();
$(this.el).html(this.template({}));
this.delegateEvents(); // this will bind all events ONCE AGAIN
This is perfect for views specially created dynamically i.e. views that are declared new under each click or so...
Events are delegated to this.el when the view is initialized. So you need to:
For the last item, if you have to do it, you can call delegateEvents once more to re-delegate the event on your view.