Page 1 of 1

mapping list of object like an array

Posted: Sun Jul 20, 2014 1:29 am
by geliz zhang

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?


mapping list of object like an array

Posted: Sun Jul 20, 2014 4:54 am
by Illya Stepanov

Hello -

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


mapping list of object like an array

Posted: Sun Jul 20, 2014 6:12 pm
by geliz zhang
  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


mapping list of object like an array

Posted: Mon Jul 21, 2014 3:01 am
by Yurii Orishchuk

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.


mapping list of object like an array

Posted: Mon Jul 21, 2014 7:10 pm
by geliz zhang

Thanks.