I do have some data in the local systems. which i am implemented with by backbone. as a doubt is it possible to sync my function with local data add or remove?
or will the backbone only work on the server response? if it work even in the localhost, how can i sync my local request i have made here?
any one looking this rquest, please don’t mind me, i am very new to backone and tight position to make a project.
code i written:
(function($){
var list = {};
list.model = Backbone.Model.extend({
defaults:{
name:'need the name'
}
});
list.collect = Backbone.Collection.extend({
model:list.model,
url : 'data/names.json',
initialize:function(){
this.fetch(); // how can i sync?
}
});
list.view = Backbone.View.extend({
initialize:function(){
this.collection = new list.collect();
this.collection.on("reset", this.render, this);
},
render:function(){
_.each(this.collection.models, function(data){
console.log(data.get('name'));
})
}
});
var newView = new list.view();
})(jQuery)
In short yes, to accomplish this you basically sync/save your data to local storage.
You could do this manually by overriding your sync method, but you will probably want to take a look at backbone.offline which is meant to do that for you.
Update:
It looks like backbone.offline is now under long reconstruction, for anyone else looking for an offline solution you might want to have a look at backbone.localStorage (which backbone.offline was in part based on but which has now been more recently updated) or at Backbone.dualStorage.