【发布时间】: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