Page 1 of 1

How to add element to Apperyio array

Posted: Wed May 27, 2015 1:13 am
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)?


How to add element to Apperyio array

Posted: Wed May 27, 2015 7:06 am
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


How to add element to Apperyio array

Posted: Wed May 27, 2015 5:43 pm
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.


How to add element to Apperyio array

Posted: Fri May 29, 2015 9:21 am
by Alena Prykhodko

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


How to add element to Apperyio array

Posted: Sun Jun 07, 2015 6:53 am
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 ?


How to add element to Apperyio array

Posted: Mon Jun 08, 2015 1:18 am
by Yurii Orishchuk

Hi LuisMa,

Please read about update functionality for storage here:

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

Regards.


How to add element to Apperyio array

Posted: Thu Feb 02, 2017 4:08 am
by Deon

Link broken due to document update. Please fix link


How to add element to Apperyio array

Posted: Thu Feb 02, 2017 4:19 pm
by Evgene Karachevtsev

Hello Deon,

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