Reputation: 83
currently I am developing an app using PhoneGap and JQueryMobile. By now, the functionality is pretty simple: All the user can do, is to create some buttons and dynamically add them to the screen.
What I want to do now, is to make this list of buttons storable. On local storage, file system... I don't know.
When the user exits the app, and then late returns, he should be able to load and extend the list he created before.
Is there any way to do that? Thanks for your help.
Upvotes: 0
Views: 45
Reputation: 1266
Given some HTML markup like this:
<html>
<body>
<div id="buttons">
</div>
</body>
</html>
You could create a button and use local storage to save it like this:
var myButton1 = "<button>My Button</button>";
window.localStorage.setItem("button1", myButton1);
And then retrieve it and display it on the page like this:
var myButton1 = window.localStorage.getItem("button1");
$("#buttons").html(myButton1);
For multiple buttons, you could store them as an array:
var myButtons = [
"<button>My Button 1</button>",
"<button>My Button 2</button>
];
window.localStorage.setItem("buttons", myButtons);
And then retrieve it and display them on the page:
var myButtons = window.localStorage.getItem("buttons");
var buttons = "";
foreach (var button in myButtons) {
buttons += button + "<br/>";
}
$("#buttons").html(buttons);
Upvotes: 1