I'm trying to do a a Backbone calendar application. I have a model Event
, an EventView
and a DailyView
.
The DailyView
loads a template which contains a table with a list of cells that represents the hour (e.g.:td #09
). I want to click the cell and obtain its id
, but when I do, I fail. I think I'm referencing the el: div
from DailyView
instead of the td
.
DailyView = Backbone.View.extend({
tagName: "div",
template: _.template($('#daily-view').html()),
events: {
'click td': 'onClick'
},
initialize: function(){
_.bindAll(this, 'render');
this.model.bind('change', this.render, this);
this.render();
},
render: function(){
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
onClick: function(){
var hour= $(this.el).attr("id");
//This doesn't work
}
I've thought of adding the cells as sub-views (sometimes empty, sometimes containing an Event
), but I don't like this approach and I'd prefer not to add more elemtns to the DOM unless it's strictly necessary.
Is there a way I can reference the td
instead of the div
?