I am writing a SPA using CanJS which has a list and user can add the list. I want to store the newly added item permanently by writing it to a file. Can some one help me?
'.btn_save click': function (ele, ev) {
var self = this;
var val = this.$input.val();
// get the currently selected model
var model = this.state.attr('selected');
// store if it is new
var isNew = model.isNew();
// update the attributes
model.attr('name', val);
// save it
model.save(function (library) {
if (isNew) {
// if new then append it to the list
self.libraries.push(library);
}
self.resetSelected();
});
return false;
},
This saves the item temporarily for the current browsing session. I want to store it permanantly.
You can save your list localy to a file using HTML5 FileWriter API. See this question. Unless using HTML5, it's not possible to save file using javascript on user's computer.