Skip to content

Instantly share code, notes, and snippets.

@enriquesaid
Last active August 29, 2015 14:17
Show Gist options
  • Save enriquesaid/d42ed9195b5ba35561f1 to your computer and use it in GitHub Desktop.
Save enriquesaid/d42ed9195b5ba35561f1 to your computer and use it in GitHub Desktop.
Backbone.View Render Template
var View = Backbone.View.extend({
template: _.template("<h1> <%= title %> </h1>"), // O template espera title como variavel
render: function() {
this.$el.html(this.template(this.model.attributes)); // Passando o title para o template
return this;
}
});
var view = new View({
model: new Backbone.Model({ title: "Título da view" }) // Passando o title pelo model
});
view.render(); // Adiciona o conteúdo da view
console.log(view.el) // Retorna: <h1> Título da view </h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment