我有以下视图,我试图将点击事件绑定到删除按钮,但它似乎没有触发任何东西。没有在控制台中发现任何错误,它似乎没有绑定“点击”事件。Backbone.js删除事件不触发
span.delete元素深深地嵌套在一堆其他元素中,不确定是否重要,我也尝试了它作为一个直接的子元素,但仍然没有去。
var ListRow = Backbone.View.extend(
{
events:
{
'click span.delete': 'remove'
},
initialize: function()
{
_.bindAll(this, 'render', 'unrender', 'remove');
this.model.bind('remove', this.unrender);
},
render: function()
{
this.el = _.template($('#tpl-sTableList_' + key + 'Row').html());
return this;
},
unrender: function()
{
$(this.el).fadeOut();
},
remove: function()
{
this.model.destroy();
}
});
是否存在“this。$ el”?所以应该是'this。$ el.html()' – HungryCoder
是的,这也适用。 – Rob