Skip to content

Instantly share code, notes, and snippets.

@vojkny
Created February 25, 2014 20:55
Show Gist options
  • Save vojkny/9217544 to your computer and use it in GitHub Desktop.
Save vojkny/9217544 to your computer and use it in GitHub Desktop.
// binds to. Override this method to prevent the initial
// events, or to add your own initial events.
_initialEvents: function(){
- if (this.collection){
- this.listenTo(this.collection, "add", this.addChildView, this);
- this.listenTo(this.collection, "remove", this.removeItemView, this);
- this.listenTo(this.collection, "reset", this._renderChildren, this);
- }
+
+ // Bind only after composite view in rendered to avoid adding child views
+ // to unexisting itemViewContainer
+ this.once('render', function () {
+ if (this.collection){
+ this.listenTo(this.collection, "add", this.addChildView, this);
+ this.listenTo(this.collection, "remove", this.removeItemView, this);
+ this.listenTo(this.collection, "reset", this._renderChildren, this);
+ }
+ });
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment