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 jQuery. Most of the time there are events, sometimes there aren't!
Are there any known things I should watch out for that can cause this?
My approach in these scenarios is to add
delegateEvents()
in render of each view that has an event, like the following: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.