1
我無法弄清楚是怎麼回事:視圖不更新的集合添加如果做視圖後創建骨幹
var times;
var t;
$(document).ready(function(){
var timeObj = Backbone.Model.extend({
setTime: function(time){
this.time = time;
return 1;
},
getTime: function(){
return this.time;
},
addTime: function(minutes){
return new Date(this.time.getTime() + minutes*60000);
}
});
var timeCollection = Backbone.Collection.extend({
model: timeObj,
});
t = new timeObj();
var now = new Date();
times = new timeCollection();
t.setTime(now);
var outputView = Backbone.View.extend({
el: "#output",
collection: times,
render: function(html){
this.$el.html(html);
},
renderTimes: function(){
var that = this;
this.collection.each(function(model){
console.log("g");
console.log(model.getTime());
that.$el.append(model.getTime()+"<br>");
});
},
initialize: function(){
this.listenTo(this.collection,"add", this.renderTimes());
}
});
times.add(t);
var t30 = t.addTime(30);
var t2 = new timeObj();
t2.setTime(t30);
var output = new outputView();
times.add(t2);
}):
它的工作,如果我把輸出創建上面的附加線。
這是應該如何工作,或者我錯過了什麼?