While data is certainly important in any application, you can't have an application without a user interface at all. On the web, this means that you have a combination of DOM elements (to display information to the user) and event handlers (to receive input from the user). In Backbone, both of these things are managed by Views; in fact, it's only fair to say that Views pretty much control all the input and output on a Backbone-powered site.
Just as Models wrap an attributes
object and Collections wrap a models
array, Views
wrap a DOM element inside a property called el
. Unlike attributes and models, however, el
is not hidden, and Backbone doesn't watch it for changes, so there's nothing wrong with referencing a View's el
directly:
someModel.attributes.foo = 'bar'; // don't do this $('#foo').append(someView.el); // feel free to do this
To create a new View
subclass, simply extend Backbone.View
in the same way as you created new Model
and Collection...