Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

backbone js
backbone events
events cheat sheet

Backbone.Events cheat sheet

Educative Answers Team

Backbone events have a variety of methods and a series of the catalog of events. Let’s look at the methods first.

Methods

The following are a few methods part of Backbone.Events.

  1. object.on(event, callback, [context]) binds a callback function to an object. The callback method will be called whenever the event is triggered.

  2. object.off([event], [callback], [context]) removes a previously-bound callback function from an object.

  3. object.trigger(event, [*args]) triggers callbacks for the given event or space-delimited list of events.

  4. object.once(event, callback, [context]) creates a backbone.Model, and it extends the backbone.Model class.

  5. object.listenTo(other, event, callback) tells an object to listen to a particular event on another object.

  6. object.stopListening([other], [event], [callback]) informs any object to stop listening to events.

  7. object.listenToOnce(other, event, callback) causes the listenTo method to only occur once before the callback function.

Events catalog

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.

RELATED TAGS

backbone js
backbone events
events cheat sheet
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring