Book Image

Learning Yeoman

By : Jonathan Spratley
Book Image

Learning Yeoman

By: Jonathan Spratley

Overview of this book

Table of Contents (17 chapters)
Learning Yeoman
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Modern Workflows for Modern Webapps
Index

The Backbone view


Backbone views are used to reflect data; they are used to listen to events and respond accordingly. The idea is to organize the user interfaces into logical views that have methods to handle user interaction and can update the UI independently when the model data changes, without having to refresh the page.

Creating views

To create a new view, use the backbone:view subgenerator as follows:

$ yo backbone:view posts

The preceding command creates a new Backbone view located at app/scripts/views/posts.coffee and a new Handlebars view template located at app/scripts/templates/posts.hbs.

Using views

Backbone views use an optional render() method that defines the logic to render a template. This example uses the Handlebars templating library to compile a collection with HTML that gets injected into the view's el property.

Open the app/scripts/views/posts.coffee file and add the following code:

define [
  'jquery',
  'underscore',
  'backbone',
  'templates',
  'collections/posts',
...