[英]View events not firing - backbone
目前,我正在構建視圖,當我單擊.organisation
鏈接時,我想觸發我的編輯事件,但是,在單擊此元素時,什么也沒有觸發,所以我不明白為什么。
這是構建我的觀點的代碼,
App.Views.groupsView = Backbone.View.extend({
el: '.app',
template: _.template( $('#tpl-groups-base').html() ),
events: {
},
initialize: function(options) {
this.render();
},
render: function() {
this.$el.html( this.template() );
var orgTab = new App.Views.OrganisationsTab({
collection : new App.Collections.Organisations
});
},
});
App.Views.OrganisationsTab = Backbone.View.extend({
el : '#organisations',
initialize: function() {
App.Collections.OrganisationCollection = this.collection;
this.collection.fetch();
this.collection.on('sync', this.render, this);
},
render: function() {
this.addAll();
return this;
},
addAll: function() {
App.Collections.OrganisationCollection.each(this.addOne, this);
},
addOne: function(organisation) {
var view = new App.Views.OrganisationView({
model : organisation
});
this.$el.append( view.render().el );
}
});
App.Views.OrganisationView = Backbone.View.extend({
tagName: 'a',
className:'group group--panel col-sm-3 organisation',
template : _.template( $('#tpl-single-group').html() ),
events: {
"click body" : "edit",
},
initialize: function() {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destory', this.remove);
},
render: function() {
this.$el.html( this.template({
group: this.model.toJSON()
}));
return this;
},
edit: function(e) {
e.preventDefault();
console.log(this.model);
}
});
為什么我不能單擊在最終視圖中創建的組織並觸發我的編輯功能?
如果要將click事件偵聽器附加到視圖el的子元素上
events: {
"click .organisation" : "edit",
},
如果您想將其附加到El
events: {
"click" : "edit",
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.