Page 1 of 1

Array mapping doesn't iterate through every object

Posted: Mon Dec 01, 2014 4:33 pm
by Deki

Hi,
I have an array in localStorage and the mapping below. There is an array called 'metrics' that contains 3 objects- waist, CRP and glucose. The problem is when I want to display the 3 objects and values in them it only shows the first object, which is waist. The other two don't get displayed on the screen.
Image

When I look at the object, I see that the other two are there (CRP and glucose) but only waist shows up in the results/screen.
Image

This is the results I get. Currently the UI consists of a "grid" component and labels inside that grid.
Image

This is my DESIRED results (i.e. what I want to show)
Image


Array mapping doesn't iterate through every object

Posted: Mon Dec 01, 2014 6:53 pm
by Evgene Karachevtsev

Hello Deki,

Your mapping on the page for this service response is wrong. Please map your metrics to mobile grid component.


Array mapping doesn't iterate through every object

Posted: Mon Dec 01, 2014 9:05 pm
by Deki

The problem with that is that I get 3 different rows like the picture below. I only want 1 row with all of the results....I don't want them listed like below. Please see my screen labeled "DESIRED result" in my initial question.

Image


Array mapping doesn't iterate through every object

Posted: Mon Dec 01, 2014 9:50 pm
by Evgene Karachevtsev

Deki,

Mapping works only for all results.
To make it one row, please rewrite your where query, so in the result will be only one row.


Array mapping doesn't iterate through every object

Posted: Mon Dec 01, 2014 10:03 pm
by Deki

Evgene, I'm not sure how to rewrite my query so that the result will be one row. Can you please tell me what I need to do or give me a hint? I'm using a standard Appery database read service. Thanks


Array mapping doesn't iterate through every object

Posted: Tue Dec 02, 2014 2:27 am
by Yurii Orishchuk

Hi Deki,

The problem is in your object.

Unfortunatly you can not map such object to the components.

The problem is - you have an array with different data inside.

Arrays in Appery.io used to link some arrays in components(like lists or grids) in items.

Thus you need:

  1. store needed values into other object. with format:

    pre

    {
    "waist": "1",
    "crp": "2",
    "glucose": 3
    }

    /pre

  2. Then you can make direct links into your components.

    Regards.


Array mapping doesn't iterate through every object

Posted: Tue Dec 02, 2014 6:56 pm
by Deki

Yes, but I want to associate other fields with the 'waist', 'crp' and 'glucose'. For example I want to include thins such as 'normal' for each one of those.

For example
waist:45, normal:yes
crp:54, normal:no


Array mapping doesn't iterate through every object

Posted: Tue Dec 02, 2014 9:51 pm
by Evgene Karachevtsev

Deki,

Like Yurii said, you need to have one collection that has all columns
"waist" , "crp" , "glucose" in it and make service that collects them all in one object.
Your result should be like in Yurii example
pre{
"waist": "1",
"crp": "2",
"glucose": 3
}/pre
Then you can map it to your components without any issues.


Array mapping doesn't iterate through every object

Posted: Wed Dec 03, 2014 1:39 am
by Deki

Guys, I'm sorry but I still don't understand what you mean....can you please explain it in a visual way? Some kind of image or picture?


Array mapping doesn't iterate through every object

Posted: Wed Dec 03, 2014 6:20 pm
by Evgene Karachevtsev

Deki,

1) the collection creating
http://gyazo.com/6e1934a61a9c45929fac...

2) the service testing
http://gyazo.com/f5a8fdd166b4df3bea98...

3) setting page with grid and labels
http://gyazo.com/2a1a2e0de862672dae50...

4) mapping the array of objects to the elements on the page
http://gyazo.com/ce1299a436b9670ea208...

5) testing the app in a browser
http://gyazo.com/5a721c0b5f4c31d9832b...