backbone.js events not firing after re-render

前端 未结 4 513
孤城傲影
孤城傲影 2020-12-24 07:08

[EDIT: I solved earlier problem by calling delegateEvents(), but shouldn\'t have to. Re-posting w/more info.]

I have a View that when rendered has a login button on

4条回答
  •  萌比男神i
    2020-12-24 07:33

    I found a solution to this, because I was having the same problem, actually detach() is not the solution because it will bring back the old DOM elements for you which is not useful.

    this is what you need to do

    render: function(){ this.$el.empty();  ......  this.$el.appendTo($DOM);   }
    

    if you use the .html() method your events will not trigger. you need to attach the newly created HTML to the DOM, by using appendTo().

    by the way this only happened to me if you are using tagName and className to build your view dynamically.

提交回复
热议问题