backbone.jsCollection


Syntax

  • // New custom collection
    var MyCollection = Backbone.Collection.extend(properties, [classProperties]);
  • // New collection instance
    var collection = new Backbone.Collection([models], [options]);

Parameters

ParameterDetails
propertiesInstance properties.
classPropertiesOptional. Properties that exist and are shared with every collection instance of this type.
modelsOptional. The initial array of models (or objects). If this parameter is left out, the collection will be empty.
optionsOptional. Object which serves to configure the collection and is then passed to the initialize function.

Remarks

Collections are ordered sets of models. You can bind "change" events to be notified when any model in the collection has been modified, listen for "add" and "remove" events, fetch the collection from the server, and use a full suite of Underscore.js methods.

Any event that is triggered on a model in a collection will also be triggered on the collection directly, for convenience. This allows you to listen for changes to specific attributes in any model in a collection.