我讀這一個,但因爲沒有答案,這個問題似乎無關緊要。我想再問一遍。我完全按照骨幹文檔頁面的指示完成,但沒有獲得任何結果。有人能幫我指出這裏出了什麼問題嗎? 代碼如下:骨幹事件再次
App.View.Task = Backbone.View.extend({
tagName: 'li',
template: _.template($("#taskTemplate").html()),
event: {
'click #edit': 'editTask'
},
editTask: function() {
alert("test");
},
render: function() {
this.$el.html(this.template(this.model.attributes));
return this;
}
})
index.html頁面看起來是這樣的:
<script id="taskTemplate" type="text/template"> <button class="edit">edit</button> <button>delete</button> </script>
,使這個$ el.html(this.template(this.model.attributes))這個$ el.html(this.template(this.model.toJSON())); – jrsalunga
可能;而一般常見的做法@petwho可能有他不希望在'toJSON'輸出,他確實想提供給他的模板屬性。使用'attributes'爲模板提供動力本質上沒有任何問題。 – machineghost