I know we can create our own events in Backbone.js like
object.trigger(‘myEvent’);
I also know there are some default events like the change or change:<attributename>
now i’m wondering, is there a list somewhere of these default events?
i am looking for a specific event that triggers when someone navigates away from a view,
so either in the removing of the view, or perhaps when a route is changed,
I just hope i don’t have to hack in my own event and it can’t hurt to see a full list of these events for further reference.
update seems like the list did exist already, as benoit describes in the comment above,
it can be found here… http://documentcloud.github.com/backbone/#FAQ-events
so it seems such a list does not exist, well, i took it upon me to go through the annotated source and present the list here for everyone who might ever need it.
i do also make this a community wiki post, so i hope it will be updated by any of you who feel the need to. whether a new Backbone version comes with extra events or i’ve got something wrong, feel free to edit.
here goes the list of events triggered by backbone itself:
change:<attributename>fired after using
model.set({<attributename>, 'value'});to indicate the attribute was changed.
changefired after using
model.set({<attributename>, 'value'});to indicate the model was changed. this fire’s on any attribute you change.
destroyfires after you destroy a model,
model.destroy({options});errorfires after a model is validated and 1 of the validations fails,
if however a specific error callback function is passed in, that one will
be executed instead of the
errorevent.also fires when you do NOT give an error callback to the following model methods:
resetfired when a collection is sorted through the
collection.sort({options});methodalso fired when specifically asking to reset a collection through
collection.reset(models, {options});addfired when a model is added to a collection
collection.add(models, {options});removefired when a model is removed from a collection…
collection.remove(models, {options});