Ok guys so I have this array of key pair values which I'm using as my model:
var acs = [{'label':'input box'},{'label':'text area'}];
the rest of the code goes as follows
var Action = Backbone.Model.extend({});
var action = new Action(acs);
var ActionView = Backbone.View.extend({
tagName:"li",
template: _.template($('#actions-template').html()),
events:{
"click":"makeInput"
},
render:function(){
$(this.el).html(this.template(this.model.toJSON()));
$(".hero-unit>ul").append(this.el);
return this;
},
makeInput:function(){
alert("im in");
}
});
var actionView = new ActionView({model:action});
actionView.render();
The question is with regards to the view. How can I loop through the model I'm passing if this is the view I want to have
<script type="text/template" id="actions-template">
<% _.each(action, function(acs) { %>
<a class="btn"><%= label %></a>
<% }); %>
</script>
There is something wrong with my view and the loop I believe. Any clues? Thanks!