【问题标题】:Backbone collection.where error骨干collection.where错误
【发布时间】:2016-01-08 12:29:13
【问题描述】:

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

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

会给我选定的模型,我可以迭代它(对于选定的模型)并设置模型。但我无法获得@where to work,而是获得:

Uncaught TypeError: _.matches is not a function

来自骨干:

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.js coffeescript underscore.js


    【解决方案1】:

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

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

    【讨论】:

    • 啊!很好的发现。万分感谢。知道这是非常简单的事情...只要我的代表足够高就为链接+1
    猜你喜欢
    • 1970-01-01
    • 2013-04-28
    • 2013-07-26
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多