Backbone collection.where 错误

Backbone collection.where error

我认为我在做一些愚蠢且明显错误的事情,但我感到困惑。使用 CoffeeScript 和 marionette backbone,我想在我的集合上创建一个方法,将大多数模型设置为选中,然后将所有选中的设置为未选中。我假设

deselectAll: ->
  @where({selected: true})

会为我提供选定的模型,我可以对其进行迭代(对于选定的模型)并设置模型。但是我无法得到@where to work 而是得到:

Uncaught TypeError: _.matches is not a function

从 backbones:

where: function(attrs, first) {
  var matches = _.matches(attrs);
  return this[first ? 'find' : 'filter'](function(model) {
    return matches(model.attributes);
  });
},

更新

目前正在使用过滤器:

@filter (model) ->
  model.get 'selected'

它似乎比以前更复杂,但也许不是?

backbone <= 1.2.1underscore >= 1.8.0 不兼容。将您的 backbone 升级到 1.2.2 或 1.2.3。

underscore 1.8.0 中,函数 matches 已弃用并重命名为 matcher。参见 underscore changelog