Created
May 30, 2013 22:10
-
-
Save nmoliveira/5681667 to your computer and use it in GitHub Desktop.
Simple Html page using Backbone View to render a 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
<html> | |
<head> | |
<title>Backbone Trainning</title> | |
</head> | |
<body> | |
<script src="scripts/jquery-1.10.0.js"></script> | |
<script src="scripts/underscore.js"></script> | |
<script src="scripts/backbone.js"></script> | |
<!-- Template --> | |
<script id="myData-tmpl" type="text/html"> | |
<p>Name: <%= myName %></p> | |
<p>Age: <%= myAge%></p> | |
</script> | |
<script type="text/javascript"> | |
// Backbone View | |
var V = Backbone.View.extend({ | |
render: function () { | |
var data = { | |
myName: 'Nuno Oliveira', | |
myAge: 32 | |
} | |
var template = $('#myData-tmpl').html(); | |
this.$el.html(_.template(template, data)); | |
return this; | |
} | |
}) | |
// create instance of V and render it | |
var myV = new V({ el : 'body' }); | |
myV.render(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment