I have a template in underscore having a button inside it. I want a click event to be mentioned in the event hash in the backbone view.
template code is:
<script type="text/template" id="ledgerListing">
<button class="btn btn-danger pull-right" id="addLedgerButton">Add Ledger</button>
</script>
View Code is:
app.ledgerView=Backbone.View.extend({
el:"#container",
template:_.template($("#ledgerListing").html()),
events: {},
initialize: function(){
},
render: function()
{
this.$el.html(template())
}
});
Now how to specify the click event in the event hash for the button with id addLedgerButton
Your can add events as the following, (format should be
event typeanda spaceandthe elementand define a function named
myclick:Here is jsfiddle. http://jsfiddle.net/w2jm7/