我想覆蓋已被繼承的事件。我有這個想法從here骨幹視圖不會覆蓋繼承事件
但是不管我怎麼努力也不會取代原來的事件:
父視圖:
SD.defaultView = function(){ //Default controller for all views
//extend the view with the default home view
var HomeView = Backbone.View.extend({
el: 'body > shell',
events: { //Add click events for global clicks
'click footer saveBox': 'saveBox',
},
render: function() {
//make sure we are logged in, if we are not forward back to home page
SD.login.checkLoginState();
//Output correct tempalte
this.$el.html(templatesNeeded);
},
saveBox: function(){
//Now we have added the who reload the sex details page.
SD.pageLoad(SD.CURRENTSEX);
},
});
SD.DV = new HomeView();
SD.DV.render();
return HomeView;
}();
子視圖:
//set up homeview
var whoAdd = SD.defaultView.extend({
el: 'page',
events: function(){
return _.extend({},SD.defaultView.prototype.events,{
'keyup #who': 'otherFunctions',
'click addContact': 'otherFunctions',
'click footer saveBox' : 'addWho'
});
},
template: JST['app/www/js/templates/details/whoAdd.ejs'],
addWho: function(el){
c(el);
},
render: function() {
myself = this;
this.$el.html(this.template);
$('save').addClass('disabled');
SD.setTitle('Who was involved?');
}
});
目前saveBox
將被正常綁定。然而,我所看到的所有例子都不像我那樣發起觀點。我從一個自動執行的函數返回視圖,但這不應該導致問題,我認爲繼承可能會在某些地方出現。
你倆的答案的幫助嗎? – bejonbee