Page 1 of 2

Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 12:27 am
by Scott Covert

My REST service returns a mixed type JSON response. I am trying to iterate over the response with two list item components stacked on top of each other. I've mapped the JSON data to both and then added some JS into each list item on the component side to hide the element if the data type is for the other list. This way, the 1st list should show the 1st data type, and the 2nd list should show the other. Unfortunately, only the first mapping created in the editor works (if I delete the working list mapping and then recreate it, suddenly the other list becomes the one that behaves properly). Any ideas? Thanks!


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 12:31 am
by maxkatz

Please share a screen shot of the mapping and if possible a sample JSON response.


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 1:04 am
by Scott Covert

Thanks Max, just sent a note to your a href="mailto:max@exadel.com" rel="nofollow"max@exadel.com/a email address with the screenshots and sample JSON.


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 2:56 am
by maxkatz

Is that the actual JSON? What I have fails validation on jsonlint.com.


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 3:01 am
by Scott Covert

It is from the service's documentation-they shortened some of the array values to make it easier to read-I'll send you a true response shortly. The only problem is the service sometimes only returns one type, but I will try to send a sample with a mixed response.


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 4:19 am
by maxkatz

If you get two differences JSON responses from a service, this is what you can do.

Let's say one response is:
{"name": "some name"}

and another response is:

{"error":"some error"}

then the Response tab structure would have both defined:

name
error

whichever the response you get, one of them would be matched.


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 4:39 am
by Scott Covert

Thanks Max, actually I get a single response but there is a field returned in the response named "type" This is the field I use to determine which list component should be populated by the rest of the response's data. So the single response returns the same fields regardless of type, but the type a fields are null for the type b elements and vice versa.


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 4:59 am
by maxkatz

So, based on 'type' value you want to decide to which components to map on the page?


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Sat Nov 16, 2013 5:22 am
by Scott Covert

Yes, and that part seems to be working. Were you able to look at the screen shots? I have to (at least as I understand it) send the data from the response to both lists, which typically would just make duplicates. However, I have JS on both lists to the effect of: if !type=a then element.hide() for the first list and if !type=b then element.hide() for the second. The iteration is actually working-let's say I have a response with 4 type a elements and 1 type b element, then the first list does show 4 items and the second only shows 1. However, for some reason the mappings for the true response data within each lists' elements (text, etc.) only works properly for the most recently created mapping. So in the editor if I create a mapping from the data to list b and then also to list a only list b fully works. If I then delete list's b's mapping and then recreate it, now only list a's mappings work. Maybe hopping on a quick Skype session would be easier for explaining the issue?


Mapping a Mixed Type JSON Response to Multiple List Item Components

Posted: Mon Nov 18, 2013 5:08 am
by Scott Covert

UPDATE: I never was able to get this working with the editor but created a mapping from the response manually with JS code and now it is working properly.

Thanks to the support team (especially Max) for their swift help in squashing this bug :-)