BackboneJS - Events
Events are capable of binding objects and trigger custom events i.e. you can bind the custom events by using the desired name of our choice.
The following table lists down all the methods which you can use to manipulate the BackboneJS-Events −
|S.No.||Methods & Description|
It binds an event to an object and executes the callback whenever an event is fired.
It removes callback functions or all events from an object.
It invokes the callback functions for the given events.
It extends the backbone.Model class while creating your own backbone Model.
It informs one object to listen to an event on another object.
It can be used to stop listening to events on the other objects.
It causes the listenTo occur only once before the callback function is being removed.
Catalog of Built-in Events
BackboneJS allows the use of global events wherever necessary in your application. It contains some of the built-in events with arguments as shown in the following table −
|S.No.||Events & Description|
"add"(model, collection, options)
It used when a model is added to the collection.
"remove"(model, collection, options)
It removes a model from the collection.
It is used to reset the collection content.
It is used when a collection needs to resorted.
It is used when changes are to be made to a model's attributes.
"change:[attribute]"(model, value, options)
It is used when there is an update in an attribute.
"destroy"(model, collection, options)
It fires when the model is destroyed.
"request"(model_or_collection, xhr, options)
It is used when a model or a collection starts requesting to the server.
"sync"(model_or_collection, resp, options)
It is used when a model or a collection is synced successfully with the server.
"error"(model_or_collection, resp, options)
It activates when there is an error in requesting to the server.
"invalid"(model, error, options)
When there is a fail in model validation, it returns invalid.
When there is a specific route match, this event can be used.
It is used when there is a match with any route.
"route"(router, route, params)
It is used by history when there is a match with any route.
It fires for all the triggered events by the passing event name as the first argument.