1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| var Book = Backbone.Model.extend({ defaults: { title: 'untitled', category: 'none' }, urlRoot: '/books', idAttribute: 'id' });
var book1 = new Book({title: 'javascript', category: '개발'}); var book2 = new Book({title: 'photoshop', category: '디자인'});
var Books = Backbone.Collection.extend({ model: Book, url: '/books', initialize: function(){ this.on('add', function(model, collection){ console.log('컬렉션의 add이벤트 핸들러 반응함'); });
this.on('remove', function(model, collection){ console.log('컬렉션의 remove이벤트 핸들러 반응함'); });
this.on('change:title', function(model, value){ console.log('컬렉션의 change이벤트 핸들러 반응함'); }); } });
var books = new Books();
books.add([book1, book2]);
|