Scott Covert
Posts: 0
Joined: Fri Nov 15, 2013 5:45 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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

Scott Covert
Posts: 0
Joined: Fri Nov 15, 2013 5:45 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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

Scott Covert
Posts: 0
Joined: Fri Nov 15, 2013 5:45 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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.

Scott Covert
Posts: 0
Joined: Fri Nov 15, 2013 5:45 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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

Scott Covert
Posts: 0
Joined: Fri Nov 15, 2013 5:45 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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?

Scott Covert
Posts: 0
Joined: Fri Nov 15, 2013 5:45 pm

Mapping a Mixed Type JSON Response to Multiple List Item Components

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 :-)

Return to “Issues”