Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Reading multiple DB records into storage model

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.

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

Reading multiple DB records into storage model

Hello Hawk,

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

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Reading multiple DB records into storage model

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,

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

Reading multiple DB records into storage model

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"

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Reading multiple DB records into storage model

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.

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

Reading multiple DB records into storage model

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

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Reading multiple DB records into storage model

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?

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

Reading multiple DB records into storage model

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

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Reading multiple DB records into storage model

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

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

Reading multiple DB records into storage model

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]

Return to “Issues”