Mac Strait
Posts: 0
Joined: Thu May 07, 2015 5:03 pm

Setting Local Storage variable that is an Array

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?

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

Setting Local Storage variable that is an Array

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

Mac Strait
Posts: 0
Joined: Thu May 07, 2015 5:03 pm

Setting Local Storage variable that is an Array

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?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Setting Local Storage variable that is an Array

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.

Malgorzata
Posts: 0
Joined: Tue Apr 18, 2017 1:21 pm

Setting Local Storage variable that is an Array

Hi, would this work for ionic app too?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Setting Local Storage variable that is an Array

Hello,

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

Return to “Issues”