I have this model –
class pt.SearchResultModel extends Backbone.Model
defaults:
id:"",
image:"",
colour:""
I am trying this –
_.pluck(resultsCollection,'id')
But it keeps returning undefined – not sure what’s going on.
What syntax error am I making?
The Underscore array methods are embedded (so to speak) into Backbone collections. You can call them directly on them:
In most of the cases you could also use the Underscore methods over the collection’s
modelsattribute (which is a plain-old array), like_.pluck someCollection.models, 'someAttr', but notice that the case ofpluckis special, as Backbone models will usually not have their attributes as own properties (you have to callgetto access them). The implementation of Backbone’spluckis very straightforward nevertheless 🙂