Backbone events have a variety of methods and a series of the catalog of events. Let’s look at the methods first.
The following are a few methods part of Backbone.Events
.
object.on(event, callback, [context])
binds a callback function to an object. The callback method will be called whenever the event is triggered.
object.off([event], [callback], [context])
removes a previously-bound callback function from an object.
object.trigger(event, [*args])
triggers callbacks for the given event or space-delimited list of events.
object.once(event, callback, [context])
creates a backbone.Model, and it extends the backbone.Model class.
object.listenTo(other, event, callback)
tells an object to listen to a particular event on another object.
object.stopListening([other], [event], [callback])
informs any object to stop listening to events.
object.listenToOnce(other, event, callback)
causes the listenTo
method to only occur once before the callback function.
Events | Description |
---|---|
add (model, collection, options) |
When a model is added to a collection. |
remove (model, collection, options) |
When a model is removed from a collection. |
update (collection, options) |
Single event triggered after changes in models in our collection. |
reset (collection, options) |
When the collection’s entire contents have been reset. |
sort (collection, options) |
When the collection has been re-sorted. |
change (model, options) |
When a model’s attributes have changed. |
destroy (model, collection, options) |
When a model is destroyed. |
request (model_or_collection, xhr, options) |
When a model or collection has started a request to the server. |
sync (model_or_collection, response, options) |
When a model or collection has been successfully synced with the server. |
error (model_or_collection, xhr, options) |
When a model or collection’s request to the server has failed. |
invalid (model, error, options) |
When a model’s validation fails on the client. |
route (route, params) |
Fired by the router when any route has been matched. |
all |
This special event fires for any triggered event. It passes the event name as the first argument and is followed by all trigger arguments. |
Free Resources