Book Image

Backbone.js Patterns and Best Practices

By : Swarnendu De
Book Image

Backbone.js Patterns and Best Practices

By: Swarnendu De

Overview of this book

Table of Contents (19 chapters)
Backbone.js Patterns and Best Practices
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Precompiling Templates on the Server Side
Index

Summary


This chapter discussed some basic problems around Backbone models that lots of developers face, and described how we can approach these issues in our projects. We learned about basic data validation as well as getting all the error messages together from our validate method. Also, we saw how using the Backbone validation plugin can reduce our efforts when performing data validation by providing lots of inbuilt features.

If the data sent from the server has a different format from what a model expects, we now know how to override the parse() method to overcome this issue. Similarly, we override the toJSON() method to change the format of data that will be passed to the server.

For most nontrivial applications, a nested model relationship is an essential requirement, and the Backbone-relational plugin can provide a ready-made solution for that. The plugin is widely accepted by the Backbone community and a lot of projects are currently using it successfully.

There are some important topics...