gpt4 book ai didi

javascript - CanJS 将待办事项存储到文件中

转载 作者:行者123 更新时间:2023-11-28 20:36:24 25 4
gpt4 key购买 nike

我正在使用 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;
},

这会暂时保存当前浏览 session 的项目。我想永久保存它。

最佳答案

TodoMVC示例使用 localstorage 进行永久存储。如果您包含 can.localstorage.min.js 您可以像这样使用它:

var Todo = can.Model.LocalStorage({
storageName: 'todos-canjs'
}, {
});

这会将您的模型数据永久存储在浏览器本地存储中。

关于javascript - CanJS 将待办事项存储到文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15288475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com