Book Image

Backbone.js Essentials

By : Jeremy Walker
Book Image

Backbone.js Essentials

By: Jeremy Walker

Overview of this book

<p>This book offers insight into creating and maintaining dynamic Backbone.js web applications. It delves into the the fundamentals of Backbone.js and helps you achieve mastery of the Backbone library.</p> <p>Starting with Models and Collections, you'll learn how to simplify client-side data management and easily transmit data to and from your server. Next, you'll learn to use Views and Routers to facilitate DOM manipulation and URL control so that your visitors can navigate your entire site without ever leaving the first HTML page. Finally, you'll learn how to combine those building blocks with other tools to achieve high-performance, testable, and maintainable web applications.</p>
Table of Contents (20 chapters)
Backbone.js Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Events


Just as with Models, Collections have on and off methods, which can be used to trigger logic when certain events occur in their Collection. The following table shows the events that can occur:

Event name

Trigger

add

When a Model or Models is/are added to the Collection

remove

When a Model or Models is/are removed from the Collection

reset

When the Collection is reset

sort

Whenever the Collection is sorted (typically after an add/remove)

sync

When an AJAX method of the Collection has completed

error

When an AJAX method of the Collection returns an error

invalid

When validation triggered by a Model's save/isValid call fails

Collections, such as Models, also have a special all event, which can be used to listen for any event occurring on the Collection. In addition, the on method of a Collection can also be used to listen for any Model events triggered by the Models in the Collection, as shown here:

var cartoonCats = new Cats([{name: 'Garfield'}]);
cartoonCats...