Skip to content

Instantly share code, notes, and snippets.

@vikynandha-zz
Last active December 23, 2015 03:59
Show Gist options
  • Save vikynandha-zz/6577627 to your computer and use it in GitHub Desktop.
Save vikynandha-zz/6577627 to your computer and use it in GitHub Desktop.
Example to demonstrate too much boilerplate code while in Backbone.
var AnyCollectionView = Backbone.View.extend({
initialize: function() {
this.collection.on( 'add', this.appendItem, this );
},
render: function() {
this.$el.empty();
this.collection.each( this.appendItem, this );
return this;
},
appendItem: function( model ) {
this.$el.append( new AnyModelView({
model: model
}).render().$el );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment