var RowView = Backbone.View.extend({
tagName: 'li',
className: 'course-row',
events: {
"click .table-row": "rowClick" // problem here!
},
initialize: function() {},
template: _.template(tpl),
render: function() {
var rowStr = this.template({course: this.model});
$(this.el).append(rowStr);
},
rowClick: function (e) {
alert(e);
}
});
Above code defines a Backbone Row view. I'd like to create and render several several rows in a table, so I did:
data.forEach(function(rowData){
var row = new RowView({model: course, el: mountPoint});
row.render();
});
If I create 2 rows, the event is bind twice( 2 alert msg if I click on the row), 3 rows 3 times. I avoided this problem by defining the event at parent views, but if I really need attach event handler at each row, how do I avoid the double event biding problem?