I'm new with backbone.js. How can I store data in my localstorage and retrieve them? I am using jeromegn's Backbone.localStorage but why can't I add or save it into the localstorage?
Here's my collection:
var Cases = Backbone.Collection.extend({
localStorage: new Backbone.LocalStorage('dataObject'),
});
Here's my view:
var CreateCase = Backbone.View.extend({
el: '.case',
render: function(){
var template = _.template($('#create-case-view').html(), {});
this.$el.html(template);
},
events: {
'submit #caseForm': 'createCase',
'click .back': 'returnBack',
'focus #c_round': 'datePicker'
},
createCase: function(e){
var caseDetails = $(e.currentTarget).serializeObject();
var cases = new Cases();
//console.log(caseDetails);
cases.add(caseDetails, {
success: function(cases){
console.log(cases); //I CAN'T ADD/SAVE IT TO THE COLLECTION
//router.navigate('', {trigger: true});
}
});
return false;
}
});
When user submits the form it should be added to the collection.
How can I retrieve it from the collection? I used cases.fetch(); but there's no data.