【发布时间】:2014-01-22 11:28:03
【问题描述】:
var Home = Backbone.View.extend({
template: _.template($('#home-template').html()),
initialize: function (params) {
this.collection = new BlogList();
this.listenTo(this.collection, "add", this.renderBlog);
this.listenTo(this.collection, "reset", this.render);
},
render: function () {
this.$el.html(this.template({hasPrevious: this.collection.hasPrevious()}));
this.collection.each(function(item) {
this.renderBlog(item);
}, this);
return this;
},
renderBlog: function(item) {
this.$('#blog-list-container').append((new BlogPreView({ model: item })).render().el);
},
BlogPreView 是一个 Backbone.View 一个新的 BlogPreView 被多次实例化。我需要删除旧的吗?
如何删除一个backbone.view 以及在这个具体示例中如何删除?
【问题讨论】:
标签: javascript backbone.js memory-leaks backbone-views