Check out this official sample app:
I'm puzzled by the connection between the collection and its property localStorage = new Store(..)
Shouldn't this belong in the model
since you can't really do a collection.save()
anyway?
Furthermore, I attempted to implement something similar, but encountered issues
var Person = Backbone.Model.extend({
defaults: {
name:'no-name',
age:0
}
});
var Persons = Backbone.Collection.extend({
model: Person,
localStorage: new Store('Persons'),
initialize: function(){
console.log('collection initialized');
}
});
window.people = new Persons();
var p1 = new Person({name:'JC',age:24});
p1.save({text:'hello'}); //<--- Uncaught TypeError: Cannot read property 'localStorage' of undefined
Any guidance on resolving this dilemma would be appreciated.