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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 281
Registered: ‎05-31-2012
My Device: Playbook
My Carrier: o2
Accepted Solution

how to load a class array?

Hi, I have something like this:

var test = new Array();
test[0] = new Foo(51, 8);
test[1] = new Foo(51, 9);
test[2] = 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?

Plase "+Like" my post if it was helpful.
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: how to load a class array?

Hi there,


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.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.