Page 1 of 3

Reading multiple DB records into storage model

Posted: Tue Nov 04, 2014 2:08 am
by Hawk

Hi,

I'm trying to use model storage feature to capture several records of data from DB and store them locally. The DB collection contains 12 records for each user. I want read these records into localstorage such that, when the user selects to display one of them there is no delay every time s/he selects from radiobuttons.

First, is that possible?
If yes, I tried the following mapping:

Image

and the following method of reading from localstorage:

Image

But I get the error (attempt to read object by index i). I also tried this:

Image

But it only return the ONE record values.

Further, I'm following this tutorial to solve the issue (http://devcenter.appery.io/documentat...) but no luck so far

In short, what I'm trying to achieve is, there is radiogroup buttons, when the user selects one of them, the value of i will be chosen and based on that the values will be read from localstorage.

If this is not possible, what options do I have to implement this logic?

Many thanks for your help.


Reading multiple DB records into storage model

Posted: Tue Nov 04, 2014 6:13 am
by Evgene Karachevtsev

Hello Hawk,

It is possible, please watch this video tutorial about Model and Storage: http://youtu.be/N1Ufy64drQ4


Reading multiple DB records into storage model

Posted: Wed Nov 05, 2014 5:33 am
by Hawk

Hi Evgene,

I watched the video. However, I still cannot figure out how to read the data from storage model. The following is my current structure:

Model:
Image

Storage:
Image

Mapping on success (on request only filter by userId):
Image

So I expect to read all records into the array objects (MS_Member_Points_Details_Array). However, when I use the following script (with any value of i) :

Image

I get the error: Uncaught Error: Attempt to access Array by property name : 'MS_Member_Points_Details_Array'

Is my reading script wrong? or is it the model structure? If so, how to fix it?

Many thanks,


Reading multiple DB records into storage model

Posted: Wed Nov 05, 2014 11:12 am
by Evgene Karachevtsev

Hello Hawk,

Of course, there is an error, because there is no such element.
Please try something like this
preget($['MS_Member_Points_Details_Array'][ i ]['MPD_Month'])/pre
I.e. without external double quotes, otherwise, instead of the index you pass just the letter "i"


Reading multiple DB records into storage model

Posted: Thu Nov 06, 2014 9:35 am
by Hawk

Hi Evgene,

Sorry but I'm still stuck at this. When I used your method, for example with i = 4, I get the error:

Cannot read property '4' of undefined!

When I used get(), without any thing inside and I put in alert, the alert displays:

pre[object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object] /pre

Ten items, which is the exact number I expect, but not this text, I expect my numbers from DB.

Your help is deeply appreciated.


Reading multiple DB records into storage model

Posted: Thu Nov 06, 2014 12:23 pm
by Evgene Karachevtsev

Hawk,

Please read this documentation:
http://devcenter.appery.io/documentat...
You need to use this API like this:
preApperyio.storage.storageVariable.get($['MS_Member_Points_Details_Array'][ i ]['MPD_Month'])/pre


Reading multiple DB records into storage model

Posted: Thu Nov 06, 2014 12:39 pm
by Hawk

So I don't replace ( storageVariable ) with my variable as I mentioned in my second post? This is what I used:

preApperyio.storage.MS_Member_Points_Details_Array.get($['MS_Member_Points_Details_Array'][ i ]['MPD_Month'])/pre

But this did not work. Is my storage model correct? How about the mapping?


Reading multiple DB records into storage model

Posted: Thu Nov 06, 2014 2:01 pm
by Evgene Karachevtsev

Hawk,

I'm sorry for the misunderstanding.
in your case the code should be
preApperyio.storage.MS_Member_Points_details_array.get("$['MPD_Month']");/pre
It should return an array of values of parameter MPD_Month


Reading multiple DB records into storage model

Posted: Fri Nov 07, 2014 11:24 am
by Hawk

Hi Evgene, I used the following

prevar bonus = Apperyio.storage.MS_Member_Points_Details_Array.get("$['MPD_Month']");
alert(bonus);/pre

It did not display the alert, rather, it returned the error: Mapping Expression is incorrect


Reading multiple DB records into storage model

Posted: Fri Nov 07, 2014 12:14 pm
by Evgene Karachevtsev

Hawk,

According to the screenshot there should be such name MS_Member_Points_Details_array (array should be in small letters).
i.e. the result should be such
prevar bonus = Apperyio.storage.MS_Member_Points_Details_array.get("$['MPD_Month']");/pre
Please note, that this will be an array and if it is displayed in the alert, it will be something like [Object Object]