Is it a method in backbone that will take a collection of models and made an array of model id's or any other specified attribute in the model?
I'm able to list the model's is's in the console.log but unsure how to make an array from it
for (var i=0; i<collection.models.length; i++){
console.log(collections.models[i].id)
}
Is it a method in backbone that will take a collection of models and made an array of model id's or any other specified attribute in the model?
I'm able to list the model's is's in the console.log but unsure how to make an array from it
for (var i=0; i<collection.models.length; i++){
console.log(collections.models[i].id)
}
Share
Improve this question
asked Dec 3, 2012 at 17:34
user240993user240993
1 Answer
Reset to default 9You can use the Underscore method pluck
for this:
collection.pluck("id");
http://jsfiddle/upqqL/
Description of pluck
from the UnderscoreJS docs:
A convenient version of what is perhaps the most mon use-case for map: extracting a list of property values.