我正在构建'待办事项列表',用户在点击后将新笔记添加到列表中。如何从本地存储阵列中删除特定项目?
我将所有附加数据保存在本地存储中。
现在我想从数组中删除单击的注释并将其保存回本地存储。 我有这样的代码:
**//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));
}
});
你能把你的代码缩小到_ [mcve] _吗?重视最低限度。 – evolutionxbox
@evolutionxbox谢谢,现在它的o.k? (我是新来的..) –
好多了。显示该问题的较短示例可帮助人们更快更准确地回答您的问题。 – evolutionxbox