Created
May 4, 2012 18:18
-
-
Save easierbycode/2596715 to your computer and use it in GitHub Desktop.
backbone 'changes' collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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