var foo = Backbone.View.extend({
tagName: 'div',
className: 'unselected',
events: {
'click div' : 'select'
},
initiate: function() {
._bindall(this, 'render' , 'select');
this.render();
},
render: function() {
$(this.el).html(_.template($("#template").html(),{...});
return this;
},
select: function() {
if (this.className == 'selected') {
this.className = 'unselected';
}
else {
this.className = 'selected';
}
this.render();
}
});
當我點擊這個div框時,className被正確更新,但html沒有更新。因此,視圖的className將更改爲「selected」,但當我檢查網頁上的div盒元素時,它仍會讀取「class =」unselected「。」。我想單擊時也要更新html。綁定視圖方法動態更改視圖的HTML類
建議或教程/文檔的鏈接將不勝感激。
問題解決了,謝謝 – 2012-07-12 01:50:06
我試圖做同樣的事情,你在哪裏插上這個代碼?謝謝。 – timeon 2013-10-18 20:42:41