문제

I have a phonegap app I'm utilising jquery mobile to display a list which I want users to be able to swipe options out to hide them - I am using this: http://jquerymobile.com/demos/1.3.0/docs/examples/swipe/swipe-list.html#demo-page

I need to have the app remember the users deletions if they were to reload the page - I'm guessing a cookie would be required however with my limited JS knowledge I'm struggling to write a cookie for the swipe to delete functions! Please help!

도움이 되었습니까?

해결책

I would use localStorage to store an array of your deleted items objects. Use JSON.stringify to convert the array to string before storing:

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));

Retrieve list from storage:

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

Here is an article with examples where localStorage is extended to add setArray and getArray prototypes: http://inflagrantedelicto.memoryspiral.com/2013/05/phonegap-saving-arrays-in-local-storage/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top