Take the 2-minute tour ×

I have a backbone.js collection with male and female models.

In my interface I want to separate them into their own individual columns. Is there a built in / recommended way to group in backbone.js collection?

Right now in my view / rendering code I'm doing

if male
if female

Is there any other way of doing it? Maybe using underscore's groupBy?


share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You could filter the collection by gender to get an array of the matching models

Person = Backbone.Model.extend();
Persons = Backbone.Collection.extend({
    model: Person,
    filterGender: function (g) {
        return this.filter(function(m) {
            return m.get("gender")==g;

l=new Persons();

share|improve this answer
add comment

Your Answer


