I applied the simple close() method to all Backbone views that have the view when it is not needed / should be reset.
Backbone.View.prototype.close = function() { if (this.onClose) { this.onClose(); } this.remove(); this.unbind(); }; NewView = Backbone.View.extend({ el: '#List ul', initialize: function() {}, render: function() { _(this.collection.models).each(function(item) { this.renderChildren(item); }, this); }, renderChildren: function(item) { var itemView = new NewChildView({ model: item }); $(this.el).prepend(itemView.render()); }, onClose: function() { this.collection.reset();
Now, when I delete the parent view, I also want to delete all child views. Any ideas how I can do this without getting stuck on such models ....
_(this.collection.models).each(function(item) { item.close(); }, this);
vikmalhotra
source share