Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  168] [ 4]  / answers: 1 / hits: 27689  / 14 Years ago, sat, february 26, 2011, 12:00:00

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?


More From » backbone.js

 Answers
9

Events are delegated to this.el when the view is initialized. So you need to:




  • Create the view by giving the constructor the el option to specify the element

  • Define el, tag, id, classname on your view to create or find on the page your element directly.

  • Append your rendered view to the el element of the view

  • Make sure you do not replace the el element after the view creation



For the last item, if you have to do it, you can call delegateEvents once more to re-delegate the event on your view.


[#93563] Friday, February 25, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
malkajillc

Total Points: 652
Total Questions: 107
Total Answers: 98

Location: Finland
Member since Sat, Nov 6, 2021
3 Years ago
malkajillc questions
;