使用滑动存储cookie以删除jquery mobile

Store cookie with swipe to delete jquery mobile

本文关键字:删除 jquery mobile cookie 存储      更新时间:2023-09-26

我有一个phonegap应用程序,我正在使用jquery mobile显示一个列表,我希望用户能够刷出选项来隐藏它们-我使用的是:http://jquerymobile.com/demos/1.3.0/docs/examples/swipe/swipe-list.html#demo-页面

如果用户要重新加载页面,我需要让应用程序记住他们删除的内容——我猜需要一个cookie,但由于我对JS的了解有限,我很难为滑动删除功能编写cookie!请帮忙!

我会使用localStorage来存储已删除项对象的数组。在存储之前使用JSON.stringify将数组转换为字符串:

var delItems= [];
delItems.push({id:"1",title:"title1"});
delItems.push({id:"2",title:"title2"});
delItems.push({id:"3",title:"title3"});
localStorage.setItem('deletedItems', JSON.stringify(delItems));

从存储器检索列表:

var delItems = JSON.parse(localStorage["deletedItems"]);

下面是一篇文章,其中包含localStorage被扩展为添加setArray和getArray原型的示例:http://inflagrantedelicto.memoryspiral.com/2013/05/phonegap-saving-arrays-in-local-storage/