11-22-2012 09:06 AM
Hi, I have something like this:
var test = new Array(); test = new Foo(51, 8); test = new Foo(51, 9); test = new Foo(50, 7); // save and load localStorage.setItem("save", test); var test2 = localStorage.getItem("save");
I have my own class called Foo and I save and load it. I wanted to have then the same in test and test2.
but when i load the stuff into test2 its not a Foo anymore. How to realize this?
Solved! Go to Solution.
11-22-2012 10:42 AM
localStorage can only save name/value pairs; essentially, strings. You can not save full objects into this storage.
This is where IndexedDB would come in, but currently has not been implemented on the platform.
The workaround here would be to save the array into localStorage as strings, potentially even with toString to avoid creating multiple entries:
Then, when you want to create your test2 array, you would need to read that entry, parse it, and populate your array programmatically rather than expecting it to be directly created by the getItem call. For the parsing step, you could use something like split.