Backbone DB
Backbone database interface and in-process reference implementation
api
var store = new DB('mymodels');
var MyModel = Backbone.Model.extend({
url: function() {
if(this.isNew()) {
return '/mymodels';
}
return '/mymodels/' + this.get(this.idAttribute);
},
db: store,
sync: store.sync
});
var me = new MyModel({username:"Nomon"});
me.save(null, {success: function() {
var me2 = new MyModel({id:me.get(me.idAttribute)});
me2.fetch({success: function(model) {
console.log("My username:",model.get('username'));
}});
}, error: function(err) {
console.error(err);
}});