Using a field from a collection as a header item in a table / grid?


#1

Ok, i’m sure this is simpler than I’m making it, but so far…no luck.

I have a collection like:

{ 
    _id: id1,
    subType: Water,
    division: city,
    number: CW1
},
{
    _id: id2,
    subType: Water,
    division: county,
    number: WCO1,
},
{
    _id: id3,
    subType: Street,
    division: city,
    number: SC1,
},
{
    _id: id4,
    subType: Street,
    division: city,
    number: SC2,
},
{
    _id: id5,
    subType: Street,
    division: county,
    number: SCO1,
}

etc.

My goal is to pull this data and group the results by SubType, and display each item under that subType heading in a table or grid.

I can get the data and loop through with a #each, but can’t figure out how to only show the subType once as a group header.


#2

Use _.groupBy :wink:
http://underscorejs.org/#groupBy