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. までの範囲を反復する方法は?
モデルの配列をスライスし、結果に_.eachを使用する
var c=new Backbone.Collection(...); _.each( c.models.slice(3,11), function(model) { console.log(model.get("id")); });
スライスは0ベースであり、終了インデックスは除外されます。
スライスとは対照的に、コレクションの at メソッドを使用すると、もう少し直接的になります。
for (var idx=3;idx<=10;++idx) { var model = collection.at(idx); ...do something... }