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
Posts: 20
Registered: ‎10-09-2010
My Device: Bold 9700
My Carrier: Base (Belgium)
Accepted Solution

bbUI.js and localStorage.getItem returning nulls

Hi,

 

I'm building a WebWorks app with bbUI.js for BB10 and I'm running into problems when I want to retrieve items from localStorage. Storing them is no problem. Here is my architecture:

 

  1. index.html which uses localStorage.getItem in a ondomready function for 1 screen (fueltracker.html), this works
  2. js/register.js with all the functions like registerUser(), registerEngine(), registerBrand(), registerModel() each called when onclick in their respective screens, see below
  3. register.html calls registerUser()
  4. addCar.html calls registerBrand()
  5. addModel.html calls registerModel()
  6. addEngine.html calls registerEngine()
  7. fueltracker.html which has a few buttons whose label needs to be changed to values coming from localStorage

The various register() functions do a localStorage.setItem() call, which works (i.e. the values are being set). However, in certain cases parts of objects stored in localStorage need to be updated, so this object needs to be retrieved first, updated and then stored again. Unfortunately localStorage.getItem() calls do not return the value which is stored in localStorage.

 

So, how should this be done?

Developer
Posts: 20
Registered: ‎10-09-2010
My Device: Bold 9700
My Carrier: Base (Belgium)

Re: bbUI.js and localStorage.getItem returning nulls

Highlighted
BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: bbUI.js and localStorage.getItem returning nulls

Have you tried using Web Inspector to make sure that the variables you're setting into localStorage are actually set?  Here's some documentation on Web Inspector.

 

https://developer.blackberry.com/html5/documentation/web_inspector_overview_1553586_11.html

Developer
Posts: 20
Registered: ‎10-09-2010
My Device: Bold 9700
My Carrier: Base (Belgium)

Re: bbUI.js and localStorage.getItem returning nulls

Yes Chad, the variables are being set.

 

It's the same problem as this one: http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage (objects can't be stored in LocalStorage, only key-value pairs so objects need to be stringified before putting them in LocalStorage). Putting the getObject() en setObject() methods in index.html and using them instead of getItem() and setItem() solved the issue.