3

Multiple view instances are happening in my application when I change layouts. I think it's possibly because they use the same el but I'm not sure. How would I go about clearing out views before setting up new ones? Or should I create wrapper el element for each one and clear them from the dom instead?

Thanks!

fancy
  • 48,619
  • 62
  • 153
  • 231

1 Answers1

5

you're probably running into zombie views caused by left-over bindings to various types of events. the solution i provided here will help you with that: Disposing of view and model objects in Backbone.js

Community
  • 1
  • 1
Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
  • This worked. I'd like create this close method in a base view and give it the ability to iterate through its extended views and unbind all of their events. Have you tried anything like this? – fancy Sep 12 '11 at 19:03
  • yeah, i've done similar things. you can add a close method to the base backbone view like this: `Backbone.View.prototype.close = function(){ /* your code here */ }` – Derick Bailey Sep 12 '11 at 21:30
  • 1
    Fancy, you can also extend Backbone.View with your own base view and then have all views just extend off that. This is what I do. – Mauvis Ledford Sep 17 '11 at 05:51
  • @Mauvis - I do the same when I need a sub-set of my views to share functionality. When I want all of my views to share the functionality, I use the Backbone.View.prototype. – Derick Bailey Sep 17 '11 at 19:18