javascript - Backbone: collection of models id's to an array - Stack Overflow

Is it a method in backbone that will take a collection of models and made an array of model id's o

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
Add a ment  | 

1 Answer 1

Reset to default 9

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745144102a4613566.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信