【发布时间】:2017-07-05 17:11:44
【问题描述】:
我正在构建一个“待办事项列表”,用户在点击后将新笔记附加到列表中。
我将所有附加数据保存在本地存储中。
现在我想从数组中删除单击的注释并将其保存回本地存储。 我有这个代码:
**//Here i get the note**
var getNote = JSON.parse(localStorage.getItem("savedNotes")) || [];
$("#notes-section").append(getNote);
**//Here i set the note**
getNote.push(note);
localStorage.setItem("savedNotes", JSON.stringify(getNote));
**//Here i want to remove the note from the array**
$(document).on('click', '.pin', function() {
$(this).parent().css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0}, 2000);
for(var i =0 ; i < getNote.length; i++ ){
getNote.splice(i,1);
localStorage.setItem("savedNotes", JSON.stringify(getNote));
}
});
【问题讨论】:
-
你能把你的代码减少到 minimal reproducible example 吗?强调最小。
-
@evolutionxbox 谢谢,现在可以了吗? (我是新来的..)
-
好多了。显示问题的简短示例可帮助人们更快、更准确地回答您的问题。
标签: javascript arrays local-storage