geliz zhang
Posts: 0
Joined: Fri Jul 18, 2014 1:22 am

mapping list of object like an array

I know how to map an array response into a list or grid. But when integrating with an external api that return records as a list of object not an array, I am not lucky:
{
"converation1": {name: "John", tag:"good"},
"converation2": {name: "Mike", tag:"better"}
}

Even I can create the response parameters from the test and modify the first node into "$" and mark it as an array, the behavior is not as expected. I think it expect such a response:
[
{"converation1": {name: "John", tag:"good"}},
{"converation2": {name: "Mike", tag:"better"}}
]
But I can't control this api to change. Any suggestion?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

mapping list of object like an array

Hello -

Could you please show your service settings, request and response parameters?

geliz zhang
Posts: 0
Joined: Fri Jul 18, 2014 1:22 am

mapping list of object like an array

  1. source data
    Image

    1. automatic response structure, which is not treating result like an array

      Image

    2. I modified the field to be $, and ticked the array option
      Image

    3. The screen is very simply, just a list
      Image

    4. Mapping
      Image

      Of course, it is indeed not an array. What else simple way can I do?

      I think of using a loop going through each node, but if the UI is a complex grid, dynamically appending html code is not fun.

      Maybe have to use general service?

      Thanks

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

mapping list of object like an array

Hi Geliz,

If you need to iterate object into the list of components you need:

1 Add Generic security context.

2 Use code in this generic security context to convert object to array. For example:

pre

var yourObject = {
"converation1": {name: "John", tag:"good"},
"converation2": {name: "Mike", tag:"better"}
};

var newArray = [];

for(var i in yourObject){
var currentObject = yourObject;
currentObject["iteration"] = i;

Code: Select all

 newArray.push(currentObject); 

};

console.log(newArray);

/pre

3 use this generic security context in your service.

4 Then you will get in your service array instead of object and you wil bel able to use mapping to make ui you need.

Also please read about generic security context here:

http://devcenter.appery.io/documentat...

Regards.

geliz zhang
Posts: 0
Joined: Fri Jul 18, 2014 1:22 am

mapping list of object like an array

Thanks.

Return to “Issues”