最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论