0

I am wanting to get a list from my collection, the list will be used to add options to a select list. I am wanting to use this to filter the collection,

So for example I am want filter my collection by the group attributes, so first I need to get all the DISTINCT groups from my collection, i.e no repeats, I know I can do something like,

this.collection.where({ group: "group name"});

but is there a way to return a list of attributes for the models in a collection without having to query by a key word?

What I want in the end is something like this,

<select>
   <option>Filter by Group</option>
   <option value="organisation 1">Organisation 1</option>
   <option value="toms organisation">Tom's Organisation</option>
   <option value="Acme">Acme</option>
</select>

Is this even possible?

Udders
  • 6,914
  • 24
  • 102
  • 194
  • The models in your collection have the same attribute keys or? If so it's easy, otherwise I can't see a better way than looping over the models and collecting all the keys – Dominic Oct 28 '14 at 10:39
  • All the models will have an attribute key of group. – Udders Oct 28 '14 at 10:44

1 Answers1

1

I think you need pluck() collection method with _.uniq() Underscore method:

_.uniq(this.collection.pluck('group'))
Mironor
  • 1,157
  • 10
  • 25