Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

I have a service response mapped to a list component.

the list contains a 'mainItem' and 'alsoOpenItem'.

I want the response to map the main days to 'mainitem' and map the other days to 'alsoOpenItem'.

the way I want to distinguish between main days and other days is from the field 'NightName'. The main days have unique names. The i other days all have "Open" as there 'NightName'.

for example, other days - if 'NightName' is "Open" map to 'alsoOpenItem'.

main days - if 'NightName' is anything else, map to 'mainItem'

I want to map them to the same list, but to separate list items, so i can separate them by the 'NightName'.

Does this make sense and is it achievable?
I could use 2 separate database services with a where clause on the response but this feels like it would be a slower way of doing it.

Thanks guys.

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

split service response to different list items

Hello Joe.
1) You need to save response to LSV
2) Then split it in two different arrays(or make it during saving in #1)
3) map LSV to 2 different components

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

Thank you,

I understand this but I'm not sure what code to use to make the response split to the different storage arrays.

Can you explain this in more detail?

Thank you

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

So should I have one storage array for results where the 'NightName' is "Open", and one for results where the 'NightName' is not "Open"?

if so, do I map the service response to both storage arrays and add JS on the mapping to make it either skip or not, depending on a NightName = "Open" condition? and what code would I use to make it skip a result?

or instead of using visual mapping, should i have an on success JS event that iterates through the responses, and adds the row to the correct storage array?

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

split service response to different list items

Hi Joe,

You need:

  1. Add two LSVs ("lsvFirstArray" and "lsvSecondArray") storages to your storages. Note these LSVs should an array type.

  2. Add "success" event handler with following JS code(example):

    pre

    var firstArray = [];
    var secondArray = [];

    for(var i = 0; i < data&#46;length; i++){
    if(data&#46;NightName == "Open")
    firstArray&#46;push(data)
    else
    secondArray&#46;push(data);
    };

    localStorage&#46;setItem("lsvFirstArray", JSON&#46;stringify(firstArray));
    localStorage&#46;setItem("lsvSecondArray", JSON&#46;stringify(secondArray));

    /pre

  3. Add new "success" event handler with type "mapping". And make links from "lsvFirstArray" storage to first list. And From "lsvSecondArray" storage to second list.

    Regards.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

Thank Yurii,

worked perfectly.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

I have a follow up question.

The collection contains 10 columns, so at the moment each object is being pushed to the array with all 10 columns. I want each object in the array to only save 3 specific columns, instead of all 10.

how would I change the code to only just specific columns?

Thank you

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

I tried changing the service response to only include the specific fields but this didnt work, it still pushed all the fields for each object into the array.

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

split service response to different list items

Hi Joe,

You need to use list service with "proj" parameter.

See details here: https://devcenter.appery.io/documenta...

Example of use:

pre

'proj={"firstNeededCollumn":1, "secondNeededCollumn":1, "thirdNeededCollumn":1}'

/pre

Regards.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

split service response to different list items

perfect, thank you

Return to “Issues”