Reputation: 834
In backbone I will often instantiate views using something like...
new mysite.some.namespace.View();
Which will then load in my view and attach events to the DOM. The problem is with removing that view and then instantiating it again. My events will often double if I load the view twice. How can I eliminate this? Is this because my el is set to a wrapper element for the app?
What's an easy solution for this?
Upvotes: 2
Views: 1230
Reputation: 145994
From the comments it sounds like you have strayed off of the backbone straight and narrow path into the weeds. Proper event handling requires some care. If you post more code, we can provide more detailed suggestions, however:
.remove()
when you are done with a view instance. All DOM event bindings will be automatically removed.this.el
).this.el
. Don't specify it. Use tagName
in your extend
object if needed, but a view's el
should be A) unique to that view and B) detached from the DOM until something external to the view attaches it (usually a router or composite view manager).Upvotes: 3
Reputation: 45124
You can use e.stopImmediatePropagation();
in order to keep the event from propagating.
Upvotes: 0