4
我有一個點擊處理程序爲我的視圖,但它似乎像視圖的el
$('#modal')
點擊事件處理程序的目標點擊時不觸發。但是當我定位$('modal')
的任何孩子時,單擊事件就會觸發。點擊事件沒有開火! (backbone.js)
我猜$('#modal')
不被視爲視圖的一部分,因此在events
中定義的單擊事件處理程序不起作用。如果是這樣,還有其他解決方法嗎?而不是
ModalView = Backbone.View.extend({
el: $('#modal'),
template: _.template($('#tpl_modal').html()),
events: {
'click #modal': 'closeModal'
},
initialize: function() {
_.bindAll(this, 'render', 'renderSimilarPosts', 'closeModal');
this.render();
},
render: function() {
$(this.el).fadeIn('fast').append(this.template(this.model.toJSON(this.model)));
},
closeModal: function() {
// some code
}
});