Storing Objects to HTML5 Client-side Storage

Here is a handy tip on how to store your JavaScript objects into HTML5 client-side storage which is basically a simple key/value hashtable. You can easily store objects into a storage in JSON format.

W3C Development with TextMate and Chrome

Code that I’m using for storing the “Task” objects in my GTD app:

var jsonTasks = JSON.stringify( tasks );
localStorage.tasks = jsonTasks;

That’s it. That is quite easy and can’t really think of many languages where you can persist objects with only few lines of code.

Code that I’m using for retrieving objects from storage:

tasks = JSON.parse( localStorage.tasks );

I hope you find this helpful. It works great on Qt Web Runtime running on my Nokia N900.

  • Kikyou22

    Hi:
    would you please tell me the version of you qt wrt?
    I test the localStorage in my wrt enviroment, but it failed.
    Thank you very much!
    Br

    • Anonymous

      Qt WRT 1.1 tp3 seems to work quite well with the localStorage.

      • Kikyou22

        Have you try the “storage” event? I tried the “setItem” and “getItem” API of localStorage and it succeed but failed with the “storage” event.I am not sure if qt wrt support the “storage” event.

  • mirko

    is there a way to save the tasks permanently, so when the app is closed, the tasks will not be deleted, and will appear again at next start up?

    • mirko

      asking for both TaskFlow and MoneyFlow