Just as with Models, Collections have on
and off
methods, which can be used to trigger logic when certain events occur in their Collection. The following table shows the events that can occur:
Event name |
Trigger |
---|---|
| |
| |
| |
|
Whenever the Collection is sorted (typically after an add/remove) |
| |
| |
|
When validation triggered by a Model's |
Collections, such as Models, also have a special all
event, which can be used to listen for any event occurring on the Collection. In addition, the on
method of a Collection can also be used to listen for any Model events triggered by the Models in the Collection, as shown here:
var cartoonCats = new Cats([{name: 'Garfield'}]); cartoonCats...