2

I have a method in my collection that performs a filter.

filterByCategory: function() {
    this.collection.reset(this.collection, {silent: true});

    var filterCategory = this.filterCategory;
    var filtered = _.filter(this.collection.models, function (item) {
        return Date.parse(item.get("category")) < filterCategory;
    });

    this.collection.reset(filtered);
}

In my initialise function I then have listen to the reset event but this never gets called.

this.collection.on("reset", this.render, this);

I've checked and made sure that my collection is definitely being filter correctly. Also if I add this.render underneath this.collection.reset(filtered) that also doesn't work.

One thing I can think of is that with the collection I'm currently working with my filters either return every item in the collection or none of the items in the collection. Could it be that the reset event only gets fired if you pass it a subset of your collection that is has at least one item in it but not every item in it?

Can anyone see what I'm doing wrong?

Bender
  • 581
  • 1
  • 6
  • 20

0 Answers0