Backbone的事件系統有問題。Backbone listenTo不會作爲處理程序觸發jquery函數
是否有可能直接將jquery函數作爲回調函數傳遞?
下面的代碼不會火災顯示/隱藏方法:
initialize: function() {
this.render();
this.logoutButton = $('#logout-button');
this.logoutButton.hide();
this.listenTo(this.model, 'loginSuccessEvent', this.logoutButton.show);
this.listenTo(this.model, 'logoutSuccessEvent', this.logoutButton.hide);
},
但如果我把它改成這樣,它完美的作品:
initialize: function() {
this.render();
this.logoutButton = $('#logout-button');
this.logoutButton.hide();
this.listenTo(this.model, 'loginSuccessEvent', this.showButton);
this.listenTo(this.model, 'logoutSuccessEvent', this.hideButton);
},
showButton: function() {
this.logoutButton.show();
},
hideButton: function() {
this.logoutButton.hide();
}