リストを持つCanJSを使用してSPAを作成しており、ユーザーはリストを追加できます。新しく追加したアイテムをファイルに書き込んで永続的に保存したい。誰かが私を助けることができますか?
'.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;
},
これにより、現在のブラウジング セッションのためにアイテムが一時的に保存されます。永久保存したい。