If I store view in window.myView
variable, render it, then call in javascript console:
$('#container').html('')
and then call:
$('#container').html(window.myView.$el)
Bound events will stop working.
I'm pretty sure that is supposed to be so, but:
- why exactly it works this way?
- how to re-render subpart of view w/o losing event bindings?
- why calling
myView.render()
won't lose event bindings?
Update:
Found this article. Is that the reason?
Make sure jQuery isn’t unloading your events when you don’t want it to
If you are building an app where you create views on the fly and attach/remove them to the dom, you may have a problem. Everytime you remove a view from the dom, jQuery unloads all the events. So you can’t have a reference to a view and remove it from the dom and then re-attach it later. All your events would have been unloaded. If you wanna keep the views around, a better idea is to hide them using display:none. However, you should not abuse this and recycle views that you are not going to use for a while (and prevent memory leaks).