JSFiddle - React, Tailwind, and code Playground
by Eric Howe
HTML
<script src="http://underscorejs.org/underscore.js"></script>
<script src="http://backbonejs.org/backbone.js"></script>
<div id="view-goes-here"></div>
<script id="people-template" type="text/x-handlebars-template">
<% _(people).each(function(person) { %>
<%= partial('person', person) %>
<% }) %>
</script>
<script id="person-partial" type="text/x-handlebars-template">
<div class="person">
<h2><%= firstName %> <%= lastName %></h2>
<div class="phone"><%= phone %></div>
<div class="email"><a href="mailto:<%= email %>"><%= email %></a></div>
</div>
</script>
CSS
#view-goes-here {
padding: 50px;
border: 1px solid black;
}
JavaScript
var PeopleModel = Backbone.Model.extend({
defaults: {
"people": [
{ "username": "alan", "firstName": "Alan", "lastName": "Johnson", "phone": "1111", "email": "alan@test.com" },
{ "username": "allison", "firstName": "Allison", "lastName": "House", "phone": "2222", "email": "allison@test.com" },
{ "username": "ryan", "firstName": "Ryan", "lastName": "Carson", "phone": "3333", "email": "ryan@test.com" },
{ "username": "ed", "firstName": "Edward", "lastName": "Feild", "phone": "4444", "email": "ed@test.com" },
{ "username": "phil", "firstName": "Philip", "lastName": "Doom", "phone": "5555", "email": "phil@test.com" },
{ "username": "gerald", "firstName": "Gerald", "lastName": "Butler", "phone": "6666", "email": "gerald@test.com" }
],
"company": {"name": "Random Corp."},
"country": "England"
}
});
window.partial = function(which, data) {
var tmpl = $('#' + which + '-partial').html();
return _.template(tmpl)(data);
};
var p = new PeopleModel;
var t = _.template($('#people-template').html());
$('#view-goes-here').append(
_.template($('#people-template').html())(p.toJSON())
);