Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
smartek
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook
Accepted Solution

What is the best way to save a array of Objects and then load it?

Hi, what is the best way to save and load a array of Objects?

 

I hade a code like this, but it does not work:

var test = new Array();
test.push(new Foo("a"));
for (var i = 0; i < test.length; i++) {
	console.log(test[i]);
}
// save and load, then show again
localStorage.setItem("test", test);
var test2 = localStorage("test");
for (var i = 0; i < test2.length; i++) {
	console.log(test2[i]);
}

 the problem is, in the first log I get the things I want. The second time I get:

Uncaught TypeError: Property 'localStorage' of object [object Object] is not a function 

 

Plase "+Like" my post if it was helpful.
Developer
Philipk
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook

Re: What is the best way to save a array of Objects and then load it?

The work around to this problem is to stringify before saving and then parse before loading.

http://stackoverflow.com/a/2010948/773263

Though I've been told it's much better to use IndexDB.
_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis