module.exports = class SelectableCollection

SelectableCollection

Instance mixins that provides selection state to collection models.

When a collection is reset([]), or a selected model is removed from the collection it is no longer returned by any of the getSelected... methods. Only models that exist in the collection can be selected.

When a model is selected, model.selected=true.

Events triggered on collection

selectionsChanged - triggered whenever selections change activeModelChanged - function(activeModel){} triggered on active change

Instance variables added to collection

hasSelectableCollection - set to true on call to SelectableCollection.applyTo() if set to true, calling SelectableCollection.applyTo() has no effect.

SelectableCollection Class Methods:

applyTo(collection)

This method is used to mix SelectableCollection features into a Backbone Collection.

example:

1
2
kittensCollection = new Backbone.Collection()
SelectableCollection.applyTo(kittensCollection)

SelectableCollection Instance Methods:

getSelectedModels()

Collection instance method that returns an array of selected models

selectModel(model, selected=true, options={})

Collection instance method that selects a single model.

The model will be given a selected property of true.

The selected argument can be one of: true - model argument will be selected false - unselect model "toggle"` - invert current selected state

Example:

1
2
3
myCollection.selectModel(myModel)
console.log(myModel.selected)
# => true
selectModelById(id, selected=true, options={})

Collection instance method that selects a single model by ID.

collection.get(id) is used to get the model passed to selectModel method.

See also selectModel method for options

selectModelByIndex(index, selected=true, options={})

Collection instance method that selects a single model by it's zero based index in the collection.

See also selectModel method for options

selectAll(options={})

Collection instance method that selects all models in the collection.

A single selectionsChanged event is triggered unless options.silent==true

selectNone(options={})

Collection instance method that unselects all models. Also sets activeModel to null.

A selectionsChanged event is triggered unless options.silent==true. A activeModelChanged event is also fired

setActiveModel(model, options={})

Collection instance method that sets the current 'active' Model. Multiple models may be selected in the collection, only one model can be 'active'. The active model is also selected in the collection if not already selected.

SetActiveModel() is an optional feature. Active model can be used, as it is by tilegrid, to provide both multiple selections and a single selection within that set (the last tile added to the selections)

pass in null for model argument to unset active model

getActiveModel()

Collection instance method that returns the current active model.

setActiveIndex(index, options={})

Collection instance method that sets the active model by index in collection.

see setActiveModel for options

setActiveModelById(modelId, options={})

Collection instance method that sets the active model by id in collection.

see setActiveModel for options