O'Reilly logo

Backbone.js Essentials by Jeremy Walker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rendering strategies

Now that we've covered all of View's capabilities, it's time to return to the question of how to render a View. Specifically, let's look at the main options available to you, which are explained in the sections that follow, when you overwrite the render method.

Simple templating

The first, and perhaps the most obvious, approach for rendering is to use a simple, logic-less templating system. The render method provided in the Backbone documentation is a perfect example of this, as it relies on the Underscore library's template method:

render: function() {
    this.$el.html(this.template(this.model.toJSON()));
    return this;
}

The template method takes a string, which contains one or more specially designated sections, and then combines ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required