I am facing some architecture issue in backbonejs with nested collection. I have collection of models and inside each model it can contains collection of same model as childrens. so inside parent view render I am rendering child collection and appending its dom to parentview. It is working perfectly fine.
But on parent model change I am re-rendering its view that is causing its childrens to render again. But when parents model changes I don't to create chidldren dom as child collection have no change. Can I utilize children dom without re-rendering it. Is there any way I achieve it?
Parent View Code:
RowView.prototype.initialize = function(options) {
this.childCollection = options.childCollection;
this.listenTo(this.model, "change", this.render);
}
RowView.prototype.render = function() {
var existingControls = this.model.get("controls").toJSON();
this.childCollection = this.model.get("controls");
this.childCollection.bind('add', this.addOneChild, this);
this.childCollection.bind('reset', this.resetChildrens, this);
this.childCollection.reset(existingControls, this);
};
RowView.prototype.addOneChild = function(respModel) {
view = new RowViewChildView({
model: respModel,
parentView: this
});
this.$el.find('.childrens').append(view.render().el);
};
RowView.prototype.resetChildrens = function(currentCollection) {
this.$el.find(".childrens").html('');
return this.addAllChildrens();
};
RowView.prototype.addAllChildrens = function() {
return this.childCollection.each(this.addOneChild, this);
};
I don't want to loose child view event also.
Thanks in advance