Udders
Udders

Reputation: 6976

backbone collection get list of single attributes

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?

Upvotes: 0

Views: 1001

Answers (1)

Mironor
Mironor

Reputation: 1187

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

_.uniq(this.collection.pluck('group'))

Upvotes: 1

Related Questions