Home » Backbone.js Events

Backbone.js Events

Backbone.js Events are the modules that can be mixed in to any object. It facilitates the objects to bind and trigger the custom events by using desired name of our choice.

Following is a list of methods that can be used to manipulate the Backbone.js Events:

1.onIt binds an event to an object and executes the callback whenever an event is fired.
2.offIt removes callback functions or all events from an object.
3.triggerIt invokes the callback functions for the given events.
4.onceIt extends backbone.model class while creating your own backbone model.
5.listentoIt informs one object to listen an event on another object.
6.stoplisteningIt can be used to stop listening to events on the other objects.
7.listentoonceIt causes the listento occur only once before the callback function is being removed.

Backbone.js Built-in Events

Backbone.js facilitates you to use global events when it is needed in your application. It consist of some of the built-in events with arguments as shown in the below table:

1.“add”(model, collection, options)It is used to add model to the collection.
2.“remove”(model, collection, options)It removes the model from the collection.
3.“reset”(collection, options)It is used to reset the collection contents.
4.“sort”(collection, options)It is used when collection needs to resorted.
5.“change”(model, options)It is used when changes occur in model?s attribute.
6.“change:[attribute]”(model, value, options)It is used when there is an update in an attribute.
7.“destroy”(model, collection, options)It fires when model is destroyed.
8.“request”(model_or_collection, xhr, options)It is used when model or collection starts requesting to the server.
9.“sync”(model_or_collection, resp, options)It is used when model or collection synced successfully with server.
10.“error”(model_or_collection, resp, options)It is activated when there is an error in requesting to the server.
11.“invalid”(model, error, options)It returns invalid when a failure occurs in model validation.
12.“route:[name]”(params)This event can be used when there is a specific rote match.
13.“route”(route,params)It is used when there is a match with any route.
14.“route”(router, route, params)It is used by history when there is a match with any route.
15.“all”It is used to fire for all triggered events by passing event name as first argument.

You may also like