PacktLib: Backbone.js Cookbook

Backbone.js Cookbook

Credits

About the Author

Acknowledgement

About the Reviewers

www.PacktPub.com

Preface

Understanding Backbone

Introduction

Designing an application with the MVC pattern

Defining business logic with models and collections

Modeling an application's behavior with views and a router

Creating an application structure from scratch

Writing your first Backbone application

Implementing URL routing in your application

Extending an application with plugins

Contributing to the Backbone project

Models

Introduction

Creating a model

Operating with model attributes

Operating with the model identifier

Validating model attributes

Overriding getters and setters

Creating undo points to store/restore a model's state

Implementing workflow for a model

Using advanced validation in a model

Validating an HTML form

Working with nested attributes in a model

Implementing a one-to-one relationship

Collections

Introduction

Creating a collection of models

Getting a model from a collection by its index

Getting a model from a collection by its ID

Adding a model to a collection

Removing a model from a collection

Working with a collection as a stack or as a queue

Sorting a collection

Filtering models in a collection

Iterating through a collection

Chaining a collection

Running No SQL queries on a collection

Storing models of various types in the same collection

Implementing a one-to-many relationship

Views

Introduction

Rendering a view

Dealing with a view element using jQuery

Rendering a model in a view

Rendering a collection in a view

Splitting a view into subviews

Handling Document Object Model (DOM) events in a view

Switching views using Backbone.Router

Events and Bindings

Introduction

Managing events in Backbone.js

Handling events of Backbone objects

Binding a model to a view

Binding a collection to a view

Bidirectional binding with Backbone.stickit

Binding a model and a collection to a select list

Handling keyboard shortcuts in a view

Handling router events

Templates and UX sugar

Introduction

Using templates in a view

Implementing a template loader

Using Mustache templates

Defining a form

Adding validation to a form

Handling form events

Customizing a form with the Bootstrap framework

Assembling layouts with LayoutManager

Building a semantic and an easily styleable data grid

How it works...

Drawing on the HTML5 canvas

REST and Storage

Introduction

Architecting the REST API for the backend

Prototyping a RESTful backend with MongoLab

Synchronizing models and collections with a RESTful service

Building a RESTful frontend with Backbone

Using the polling technique to fetch data

Working with local storage

Special Techniques

Introduction

Using mixins with Backbone objects

Creating a Backbone.js extension with Grunt

Writing tests for a Backbone extension with QUnit

Mocking up a RESTful service with jQuery Mockjax in asynchronous tests

Developing a mobile application with jQuery Mobile

Building an iOS/Android app with PhoneGap

Organizing a project structure with Require.js

Ensuring compatibility with search engines

Avoiding memory leaks in a Backbone application

Index