Source language: Translate to:

localstorage key values

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

localstorage key values

Postby TinTin » Wed Sep 07, 2016 8:24 am

Is there any easy way we can obtain a list / array of keyvalues from the localstorage db?

At the moment management of the localstorage db assumes you are aware of the values to reference, if you want to delete and clear etc

Ideally I need to be able to list the keys within listbox ..

Any help would be appreciated.

Cheers
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: localstorage key values

Postby Gaev » Wed Sep 07, 2016 1:58 pm

TinTin:

Is there any easy way we can obtain a list / array of keyvalues from the localstorage db?


Does not look like you are able to do this.

At the moment management of the localstorage db assumes you are aware of the values to reference, if you want to delete and clear etc

Given that you can access only the key/value pairs associated with your own website/page, this is not an unreasonable assumption.

Ideally I need to be able to list the keys within listbox ..

Assuming that you are the one setting these key/value pairs in the first place, there are work arounds ...

a) manage them all as a "javascript object" ... but save the entire contents of this object as "a single localstorage key/value" ... use stringify() and parse() methods to accomodate the restriction that localstorage values can only be strings.

OR

b) name your keys TinTin1, TinTin2, TinTin3 etc. ... so you can retrieve them within a loop.

OR

c) whenever you store a key:value in localstorage (e.g. UK:"London", Canada:"Ottawa", Germany:"Berlin"), make sure you store the keys in another (specially designated) key/value index pair (e.g. CountryKeys:"UK,Canada,Germany") ... then use this special key to fetch list of keys whose key/value pairs need to be obtained in the ListBox.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: localstorage key values

Postby TinTin » Thu Sep 08, 2016 1:38 am

Thanks GAEV, your method of storing array within each unique key is the best bet, I've implemented that and is working very well!

Cheers!
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron