简体   繁体   中英

Phonegap - How to store text in a checklist app, even after app closes

I am planning to make my first app using Phonegap.

What I want to make is a checklist. To add an item to the checklist, the user enters an item into an input field. My issue is that I don't know how I could save those items there, even after the app is closed and opened. I want those items to stay in the checklist until the user deletes them using a delete button.

I know a little about HTML5 local storage, cookies and databases. I believe I need to use HTML5 local storage? I would like my app to be used offline (wifi off) and I don't know what storage system needs internet and doesn't need internet.

Appreciate any help, I may add addition questions to this :^)

I have used HTML5 localstorage to make a checklist app myself.

With a little knowledge of HTML and Javascript you should be able to teach yourself how to accomplish this task by learning Localstorage from w3Schools

You can achieve that with LocalStorage. It allows you to persist information offline, an even after the app/browser closes or device is rebooted.

LocalStorage only saves strings, so if you want to save other types of data, you can use JSON.stringify(yourvariable); and JSON.parse(localStorage.yourvariable);

For example:

var yourlist = {item1: "firstitem", item1status: "enabled" };

is a Javascript object, so if you want to save it:

localStorage.list = JSON.stringify(yourlist);

and then you want to retreive it later:

var thesamelist = JSON.parse(localStorage.list);

That's the basic usage, there are many more features that you can find in the documentation. Good luck with your app :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM