Skip to content

Instantly share code, notes, and snippets.

@stephendeyoung
Created February 23, 2015 12:53
Show Gist options
  • Save stephendeyoung/89f7537558a83f72ea1f to your computer and use it in GitHub Desktop.
Save stephendeyoung/89f7537558a83f72ea1f to your computer and use it in GitHub Desktop.
Marionette.CollectionView.extend({
initialize: function(options) {
this._initChildViewStorage();
this.childView = this.childView || options.childView;
this.createChildren(options);
this._initialEvents();
},
createChildren: function(options) {
this.collection.each(function(model) {
var childViewOptions = typeof this.childViewOptions === 'function' ? this.childViewOptions(model, options) : {};
var view = new this.childView(_.extend({
el: options.selector(this.$el.selector, model.get('_id')),
model: model
}, childViewOptions));
this.initializeChild(view);
}, this);
},
initializeChild: function(view) {
this.proxyChildEvents(view);
this.children.add(view);
if (view.onRender) {
view.onRender();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment