Gøran Karlsen
Posts: 0
Joined: Tue Nov 18, 2014 10:40 pm

Distinct Collapsible with List in content

Hi,

I am new to Appery, and I am having some issues with grouping results from the database.

I am using a Collapsible with a list in the content area. Let us say I have a database with two columns, name and city, and with several people in each city. I want to show Collapsibles of all cities (no duplicates) and when I expand it a list with the people in the city should appear.

My problem is that I get the same city several times.

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

Distinct Collapsible with List in content

Hi Gøran,

Unfortunatly Apperyio REST api don't allows you to group items.

I can suggest you following way to do it:

1 Create DB:
1.1. Cities: (name:string)
1.2. People: (name: string, city: pointer_toThe_Cieties.)

  1. Create "server code" that will:
    2.1. Get all cities.
    2.2. Iterate through all received cities and make separate requests (with filter by each city) to People collection.
    2.3. Combine this in nested arrays response like:

    precode

    [
    {name: "Boston", peoples: [{name: "user1"}, {name: "user2"}] }
    ];

    /code/pre

  2. User this server code as service in Appery.io application.

  3. Create two-level mapping like on screen shot: http://prntscr.com/4ggek8/direct

    Regards.

Gøran Karlsen
Posts: 0
Joined: Tue Nov 18, 2014 10:40 pm

Distinct Collapsible with List in content

Hi Yurii,

thanks! Is it also possible to get the distinct Cities from the People collection and then run separate requests for each distinct City?

And on point 2.3; this is an example of a response I get back from the requests, right? So the number of people in each city can be entirely dynamic with this solution?

BR

Gøran

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

Distinct Collapsible with List in content

Hi Gøran,

  1. Yes you can do it with Appery,io REST api.

    But in suggested DB you don't have not distinct values is not it? I specifically suggested normalized DB structure to prevent data duplicating.

  2. Yes - peoples - in this example is array and could have number of items from 0 to infinity.

    Regards.

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

Distinct Collapsible with List in content

Can this be done by mapping it out to local storage first?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Distinct Collapsible with List in content

Hello Sebastian,

Could you please specify the approach you want to try with more details?

Return to “Issues”