How to add element to Apperyio array

This forum contains topics that were moved from Get Satisfaction
Dandy Ling Kwong
Posts: 0
Joined: Sat Jan 10, 2015 9:06 am

How to add element to Apperyio array

Post by Dandy Ling Kwong »

Let's say storageVariable is an array.

I noticed that Apperyio.storage.storageVariable.set() can only set the whole array, but it can't add individual array elements. How do I do the equivalent of javascript array.push() to add individual elements to the array (storageVariable)?

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

How to add element to Apperyio array

Post by Serhii Kulibaba »

Hello Dandy,

There is no push function for storage variable. But you can use this function:

prefunction storagePush(arrayName, value){
var arr = Apperyio.storage[arrayName].get();
return Apperyio.storage[arrayName].update("$["+ arr.length +"]", value);
}/pre

1) add this function to the custom JS file
2) example of usage this function for array "myArray":

prestoragePush("myArray", "test");/pre

Dandy Ling Kwong
Posts: 0
Joined: Sat Jan 10, 2015 9:06 am

How to add element to Apperyio array

Post by Dandy Ling Kwong »

It works! Thank you.

Is there any plan to integrate this into Apperyio API? I think it is common sense for the developer to try to use Apperyio.storageVariable.push() if they think that storageVariable is an array.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

How to add element to Apperyio array

Post by Alena Prykhodko »

Thank you for idea. We've sent it to developers.

LuisMa Suárez Gutiérrez
Posts: 0
Joined: Mon Aug 18, 2014 9:12 pm

How to add element to Apperyio array

Post by LuisMa Suárez Gutiérrez »

Hi sergiy , i like your idea, can you please just elaborato on the first part of your concatenation ?
in this part

return Apperyio.storage[arrayName].update("$["+ arr.length +"]", value);

what does the $ do ?

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

How to add element to Apperyio array

Post by Yurii Orishchuk »

Hi LuisMa,

Please read about update functionality for storage here:

https://devcenter.appery.io/documenta...

Regards.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

How to add element to Apperyio array

Post by Deon »

Link broken due to document update. Please fix link

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

How to add element to Apperyio array

Post by Evgene Karachevtsev »

Hello Deon,

This is the correct link: https://docs.appery.io/reference#jque...

Post Reply