Backbone.js views delegateEvents do not get bound (sometimes)

后端 未结 2 1390
广开言路
广开言路 2020-12-14 12:26

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

2条回答
  •  情书的邮戳
    2020-12-14 13:22

    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.

提交回复
热议问题