Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

saving labels to array

Hello - in this part of the code that you have provided to us you have not defined any of the array.
localStorage - only saves a key and a value, it's only support string-to-string mappings, so you need to serialise and de-serialise other data structures. You can do so using JSON.stringify() and JSON.parse().

Please take a look at the link that Alena gives you.

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

saving labels to array

I dont understand,
the code I used saved the key but not the value, this is the only code I had, ( as example alena gave me, which was for selectmenu) if you look at the screenshots you can see the code and result.
I am not a coder, I just want to know how to save lables to an array in localstorage.
forgive me if I sound tfo. but I am

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

saving labels to array

lllya
I also have this code in add js, is it this thats needs altering, if so how?

screenshot

Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

saving labels to array

Where did you take this part of code?
presave(...);/pre
is this function is declared?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

saving labels to array

Hello! Please use method text instead val when working with Label:
preAppery("conamelabel_136").text()/pre
instead
preAppery("conamelabel_136").val()/pre

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

saving labels to array

Hi Marina,
I think I have made a mistake with app logic,
I am unsure how to effect the following

here is a screenshot to explain what I am tryng to do

Image

I have a collection of companies, when "value changes" in the selectmenu a "where" service runs and its mapped to the collapsible. All works well.

I have added a save button
I want the user to be able to save that company to their favourite list, so if the user decides to click the favourites button this favourites list appears

I first thought an array would be the way to go, but if I save all 4 labels to an array and save it to the user data db, I would have a problem mapping each label correctly

can you suggest anything?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

saving labels to array

Hi Michael,

1) In Save button handler, add handlers to save the value of the components in the localStorage, each Label in a separate variable:
http://docs.appery.io/documentation/w...

2) And one more handler, "Add JavaScript action" with the following code:
code// get current list of favorites

var favorites = JSON.parse(localStorage.getItem( "favorites" ) "[]");
// "[]" added in case variable favorites don't exists.

// names of your variables saved in actions above
var keys = ['variable1', 'variable2', ....],
i = 0,
new_item = {};

$.each(keys, function(i, key){
new_item[key] = localStorage.getItem(key);
});

// add to array
favorites.append(new_item);

// save back to the localStorage string(!)
localStorage.setItem( "favorites", JSON.stringify(favorites) );/code

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

saving labels to array

Hi,
I have done as suggested, saved all 5 variables to localstorage, and added favorites as localstorage variable

I have used the code above
screenshot

Image

error in console

Image

after clicking on error

Image

any ideas?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

saving labels to array

Hello! There are missing symbols. Should be the following line pre// "[]" added in case variable favorites don't exists./pre instead pre "[]" added in case variable favorites don't exists./pre

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

saving labels to array

Thanks Marina,
made changes,

here is the code and console error Image

Image

Return to “Issues”