Page 1 of 1

Setting Local Storage variable that is an Array

Posted: Sun Jul 05, 2015 12:21 pm
by Mac Strait

Hi I have these items in my model:
Session (of type Object)
Session_List (An array with objects of type Session)

I have the following Storage variables:
Current_Session (of type Session)
All_Sessions (Of type Session_List)

In my UI pages I use the "Set Storage variable" action to set the value for Current_Session object and it's attributes. This seems to work fine.

However when I try to populate the All_Sessions array using the "Set Storage Variable" I cannot as I do not see it in the list of storage variables to set.

What I am trying to do is store a list of Sessions, I don't know beforehand how many there will be, however no more than 50. I also want to be able to retrieve the most recent so my idea was to use the index to retrieve the Session objects in the order they were created.

Am I going about this in the right way?


Setting Local Storage variable that is an Array

Posted: Mon Jul 06, 2015 1:33 pm
by Pavel Zarudniy

Hi Mac,
You can try to use "Mapping" in "Select action" and use this doc for mapping you array - https://devcenter.appery.io/documentation/mapping/

or try "Run JavaScript" and change you variables manually as you need - https://devcenter.appery.io/documentation/model-and-storage/#Storage_API


Setting Local Storage variable that is an Array

Posted: Mon Jul 06, 2015 6:15 pm
by Mac Strait

Thanks Pavel I will give it a try and get back to you. I have another related query. When object's are successfully created in the cloud mongodb I get the created object Id as a return.

Is there such a thing when creating objects in local storage? Basically a unique id for a created object or I need to implement that myself?


Setting Local Storage variable that is an Array

Posted: Tue Jul 07, 2015 4:47 am
by Yurii Orishchuk

Hi Mac,

Just to add to the Pavels answer.

You can use JS code to new any session to session array storage.

For example:

pre

//That's how to access storages with JS
var currentSess = Apperyio.storage.Current_Session.get();
var sessions = Apperyio.storage.All_Sessions.get() || [];

//Put currentSession to session.
var insertedIndex = sessions.push(currentSess) - 1;

console.log("insertedIndex = " + insertedIndex );
//insertedIndex stores index to just created element in the array.

//Store sessions to "All_Sessions" storage.
Apperyio.storage.All_Sessions.set(sessions);

/pre

What about ID to access element in array - you can see example above i've loged it to console.

Regards.


Setting Local Storage variable that is an Array

Posted: Wed Apr 19, 2017 9:24 am
by Malgorzata

Hi, would this work for ionic app too?


Setting Local Storage variable that is an Array

Posted: Wed Apr 19, 2017 2:33 pm
by Serhii Kulibaba

Hello,

Ionic apps don't have Storage variables so it doesn't work for the Ionic app