saving an array in localstorage
Hi,
i need to save every address a user enters into a text input in local storage as an array, Have you any details on this.
thank you
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
Hi,
i need to save every address a user enters into a text input in local storage as an array, Have you any details on this.
thank you
Here is the code which saves element item to varName variable
function addItemToArray(item, varName) { var arr = JSON.parse(localStorage.getItem(varName)); if(arr == null) {arr = new Array();} arr.push(item); localStorage.setItem(varName, JSON.stringify(arr))}
Yes
Hi Marina,
I've done something wrong,
on textinput component I set action on input, set local storage, "favourites, bind to favourites, and ran the following script onclick, save to favourites button
function addItemToArray(item, favourites) { var arr = JSON.parse(localStorage.getItem(favourites)); if(arr == null) {arr = new Array();} arr.push(item); localStorage.setItem(varName, JSON.stringify(arr))}
it only saves the last entry, can tell where I went wrong
thank you for you help.
Hello! You should add this code as Custom JS without changes. It's a static code
function save(item, varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr))
}
function myload(varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
return arr;
}
Then to save an array on button click run next code
save(Tiggzi('component_name').text(), 'variable_name')
Thanks Marina,
I have included the static code in create new java,
as yesterday, the text input id is "favourites", the click button id is "favourites button".
On input event I set local storage variable, and bound favourites to favourites (text)
on favourites button I set event onclick run custom java and used the code you gave me yesterday
function addItemToArray(item, favourites) { var arr = JSON.parse(localStorage.getItem(favourites)); if(arr == null) {arr = new Array();} arr.push(item); localStorage.setItem(varName, JSON.stringify(arr))}
I have this other code you gave me today
save(Tiggzi('component_name').text(), 'variable_name')
do I run only one code onclick or both
Try to use only this code save(Tiggzi('component_name').text(), 'variable_name')
Change component names and variable names
super cool Marina,
this is the result from localstorage,
variable_favourites "["","","","","","",""]"
is there any docs on how to populate a selectmenu with this array
kind regards
Hi Marina,
this is the result in local storage in firebug, each time I save to favourites I get ,"" added to localstorage variables_favourites, but no text
I thought that the text would be there, is this correct?
variable_favourites "["","","","","","",""]"