Skip to content

Instantly share code, notes, and snippets.

@easierbycode
Created May 4, 2012 18:18
Show Gist options
  • Save easierbycode/2596715 to your computer and use it in GitHub Desktop.
Save easierbycode/2596715 to your computer and use it in GitHub Desktop.
backbone 'changes' collection
var Book = Backbone.Model.extend({});
var Library = Backbone.Collection.extend({
model: Book,
url: '/books',
initialize: function() {
this.on('add', function(model) {
console.log('added: ', model);
})
}
});
var LibraryChanges = Backbone.Collection.extend({
initialize: function(collection, options) {
this.collection = options.collection;
console.log('url: ', this.collection.url);
console.log('book 555: ', this.collection.get(555));
this.collection.add({ name:'Agile Web Development' });
}
});
var library = new Library([{ id:555, name:'Programming Your Home' }]);
var libraryChanges = new LibraryChanges([],{ collection:library });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment