| Methods | Syntax | Description |
|---|---|---|
| extend | Backbone.Collection.extend(properties, [classProperties]) | Extends the backbone’s collection class to create a collection. |
| model | collection.model([attrs], [options]) | To specify the model class, we need to override the model property of the collection class. |
| modelId | collection.modelId(attrs) | Override this method to return the value the collection will use to identify a model given its attributes. |
| preinitialize | new Backbone.Collection([models], [options]) | For use with collections as ES classes. If you define a preinitialize method, it will be invoked when the Collection is first created and before any instantiation logic is run for the Collection. |
| constructor / initialize | new Backbone.Collection([models], [options]) | When a model instance is created, it is invoked by defining the initialize function when the collection is created. |
| models | collection.models | Raw access to the JavaScript array of models inside of the collection. |
| toJSON | collection.toJSON([options]) | Return an array containing the attributes hash of each model in the collection. |
| sync | collection.sync(method, collection, [options]) | It represents the state of the model and uses the Backbone.sync to display the state of the collection. |
| add | collection.add(models, [options]) | Add a model (or an array of models) to the collection, firing an “add” event for each model, and an “update” event afterwards. |
| remove | collection.remove(models, [options]) | Remove a model (or an array of models) from the collection, and return them. |
| reset | collection.reset([models], [options]) | Adding and removing models one at a time is all well and good, but sometimes you have so many models to change that you’d rather just update the collection in bulk. |
| set | ollection.set(models, [options]) | The set method performs a “smart” update of the collection with the passed list of models. |
| get | collection.get(id) | It is used to retrieve the model from a collection by using the idor cid. |
| at | collection.at(index) | Retrieve the model from a collection by using specified index. |
| push | collection.push(model, [options]) | Add a model at the end of a collection. Takes the same options as add. |
| pop | collection.pop([options]) | Remove and return the last model from a collection. Takes the same options as remove. |
| unshift | collection.unshift(model, [options]) | Add a model at the beginning of a collection. Takes the same options as add. |
| shift | collection.shift([options]) | Remove and return the first model from a collection. Takes the same options as remove. |
| slice | collection.slice(begin, end) | Return a shallow copy of this collection’s models, using the same options as native Array#slice. |
| length | collection.length | Like an array, a Collection maintains a length property, counting the number of models it contains. |
| comparator | collection.comparator | It is used to sort the items in the collection. |
| sort | collection.sort([options]) | Sorts the items in the collection and uses comparator property in order to sort the items. |
| pluck | collection.pluck(attribute) | Pluck an attribute from each model in the collection. Equivalent to calling map and returning a single attribute from the iterator. |
| where | collection.where(attributes) | Return an array of all the models in a collection that match the passed attributes. Useful for simple cases of filter |
| findWhere | collection.findWhere(attributes) | It returns the model, that matches the specified attribute in the collection. |
| url | collection.url or collection.url() | Set the url property (or function) on a collection to reference its location on the server. |
| parse | collection.parse(response, options) | Returns the collection’s data by passing through the response object and represents the data in JSON format. |
| clone | collection.clone() | Returns a new instance of the collection with an identical list of models. |
| fetch | collection.fetch([options]) | Fetch the default set of models for this collection from the server, setting them on the collection when they arrive. |
| create | collection.create(attributes, [options]) | Convenience to create a new instance of a model within a collection. |
| mixin | Backbone.Collection.mixin(properties) | mixin provides a way to enhance the base Backbone.Collection and any collections which extend it. |