Last active
August 29, 2015 14:17
-
-
Save enriquesaid/d42ed9195b5ba35561f1 to your computer and use it in GitHub Desktop.
Backbone.View Render Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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