Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何迭代一个范围,比如说从 3. 到 10.,一个 Backbone 集合?
通过对模型数组进行切片并在结果上使用 _.each
var c=new Backbone.Collection(...); _.each( c.models.slice(3,11), function(model) { console.log(model.get("id")); });
slice是基于 0 的,并且不包括结束索引。
与切片相反,您可以使用集合的 at 方法更直接一些。
for (var idx=3;idx<=10;++idx) { var model = collection.at(idx); ...do something... }