Highway - How can I cut a collection?

I have a Backbone Collection. How can I crop a collection, or at least crop a list to a specific length?

+8
source share
1 answer

Assuming that your collection is defined and initialized, and that you want to change the collection (change it in place), you need to do:

collection.reset(collection.first(n)); 

you can use .last(n) to get the last N elements.

If you just wanted to get the first n elements without modifying the collection, just do:

 var models = collection.first(n); 

Here is a list of all underline methods that you can use directly in your collection.

+16
source share

All Articles