Page 1 of 1

Using Appery Model

Posted: Sun Mar 13, 2016 6:01 pm
by Adam Garbinski

Hello,
I am trying to implement a feature into my app that requires handling lots of data locally. User story is as follows:
1) User must be able to save to local device (not do DB) no less than 10 different meal sets.
2) Each meal set has 5 separate properties.
3) Each meal may consist of up to 7 food components.
4) Each food component has 5 separate properties.

As you can see it would require more than a hundred of separate local storage variables to handle this scenario and would be ineffective.

I tried to use Appery Model and created such structure:

Image

with local storage variable called FoodSet:

Image

I have read this tutorial here: https://devcenter.appery.io/documenta...
but somehow I am not sure if this approach is correct. My question is how can I save data that does not come from database but is generated locally on the device into Appery Model via JavaScript?
I am aware that there is GET, SET, and UPDATE in Appery API but I can't see directly how could I use it in my scenario.

I would greatly appreciate any guidance.


Using Appery Model

Posted: Mon Mar 14, 2016 7:41 am
by Serhii Kulibaba

Hello,

You are able to set any JS object to the storage variable. E.g.:

prevar FoodSet = [
{FootSetName:"one", ItemCount:1},
{FootSetName:"two", ItemCount:2}
];
Apperyio.storage.FoodSet.set(FoodSet);
/pre


Using Appery Model

Posted: Mon Mar 14, 2016 4:41 pm
by Adam Garbinski

Ok. It is getting more clear now but let me ask some more questions.
As I understand for now using SET overwrites variable value completely. So the goal here is to keep the complete object containing all data in one variable? Right?

What if I would like to for example:
1) add next FoodSet? FootSetName:"three"?
2) update number of items in FoodSet "one"?


Using Appery Model

Posted: Wed Mar 16, 2016 7:43 am
by Adam Garbinski

Hi Appery. Some more tips perhaps? I would greatly appreciate your help on that.


Using Appery Model

Posted: Wed Mar 16, 2016 12:58 pm
by Serhii Kulibaba

Please use method update() for that: https://devcenter.appery.io/documenta...


Using Appery Model

Posted: Thu Mar 17, 2016 5:31 pm
by Adam Garbinski

Thanks Sergiy but as I understand you can update existing object values but not create new one. How exactly should I use it? Like this?

var FoodSet = [
{FootSetName:"three", ItemCount:3}
];
Apperyio.storage.FoodSet.update(FoodSet);


Using Appery Model

Posted: Fri Mar 18, 2016 10:01 am
by Serhii Kulibaba

If you need to set storage variable, please use JS below:
prevar FoodSet = [
{FootSetName:"one", ItemCount:1},
{FootSetName:"two", ItemCount:2}
];
Apperyio.storage.FoodSet.set(FoodSet);/pre

If you need to update only one it's value, e.g. "one" to "three", please use method update:
preApperyio.storage.FoodSet.update("$[0]['FootSetName']", "three")/pre

here 0 - index of the item to update
FootSetName - name of the parameter to update