它是主干中的一种方法,它将采用模型集合并制作模型 ID 数组或模型中的任何其他指定属性吗?
我能够在 console.log 中列出模型的 is,但不确定如何从中创建一个数组
for (var i=0; i<collection.models.length; i++){
console.log(collections.models[i].id)
}
最佳答案
可以使用Underscore方法pluck
为此:
collection.pluck("id");
pluck
的描述来自 UnderscoreJS docs :
A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.
关于javascript - Backbone : collection of models id's to an array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13688648/