更新时间:2023-09-26 21:35:52
Underscore数组方法被嵌入到Backbone集合中(可以这么说).您可以直接在它们上调用它们:
The Underscore array methods are embedded (so to speak) into Backbone collections. You can call them directly on them:
resultsCollection.pluck 'id'
在大多数情况下,您还可以在集合的 models
属性(这是一个普通的数组)上使用Underscore方法,例如 _.pluck someCollection.models,'someAttr'
,但请注意 pluck
的情况很特殊,因为Backbone模型通常不会将其属性作为自己的属性(您必须调用非常简单不过:)
In most of the cases you could also use the Underscore methods over the collection's models
attribute (which is a plain-old array), like _.pluck someCollection.models, 'someAttr'
, but notice that the case of pluck
is special, as Backbone models will usually not have their attributes as own properties (you have to call get
to access them). The implementation of Backbone's pluck
is very straightforward nevertheless :)