JSFiddle - React, Tailwind, and code Playground
by qwweee7467
HTML
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<div id="view-goes-here"></div>
<script type="text/template" id="actions-template">
<% _.each(action, function(acs) { %>
<a class="btn"><%= acs.label %></a>
<% }); %>
</script>
CSS
#view-goes-here {
padding: 50px;
border: 1px solid black;
}
#view-goes-here div {
background: #ddd;
padding: 5px;
}
#view-goes-here a {
display: block;
background: #eee;
margin: 5px;
}
JavaScript
/* Loops in underscore js template */
var acs = [{'label':'input box'},{'label':'text area'}];
var Action = Backbone.Model.extend({});
var ActionView = Backbone.View.extend({
template: _.template($('#actions-template').html()),
events:{
"click":"makeInput"
},
render:function(){
console.log(this.model.toJSON());
$(this.el).html(this.template({
action: this.model.toJSON()
}));
$('#view-goes-here').append(this.el);
return this;
},
makeInput:function(){
alert("im in");
}
});
var action = new Action(acs);
var actionView = new ActionView({model:action});
actionView.render();