January 2016
Intermediate to advanced
278 pages
4h 53m
English
The simplest implementation is to render a single model; it's a very straightforward algorithm. Extract data from the model and use a template engine to make the actual render with the data; finally, attach the result in the DOM:
class MyView extends Backbone.View {
constructor(options) {
super(options);
template: _.template($("#my-template").html());
}
render() {
var data = this.model.toJSON();
var renderedHtml = this.template(data);
this.$el.html(renderedHtml);
return this;
}
}In the following code we can identify five steps to rendering the view.
$("#my-template").html()
_.template($("#my-template").html())
var data = this.model.toJSON()
Read now
Unlock full access