In underscore.js templates, is there a way to get the data of the template from a click event? For example:
geocoder.geocode({
'address' : $(this.el).find("input[name=locationSearchText]").val()
}, function(results, status) {
if (results && status && status == 'OK') {
this.results = results;
var list =_.template("<ul><% _.each(results, function(result){ %><li><%= result.formatted_address %></li><% })%></ul>");
$el.find("#search-results").html(list);
}else{
alert("SOMETHING WENT WRONG!");
}
});
And then in backbone on the view:
events: {
'click #search-results li': function(data){ 'the data of the `result` that was passed to the template in the each'}
},