骨干js中的View.remove()函数从DOM中删除视图本身的容器元素,防止重新创建已删除的视图.知道如何处理这种情况
这是我的代码,
var AttributeView = Backbone.View.extend({
el: $("#attrs"),
template:_.template($('#attrs-template').html()),
initialize:function() {
},
render:function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
dispose:function(eventName){
this.unbind();
this.remove();
},
});
var attrView = new AttributeView();
....
attrView.dispose();
//Later on some event I do the below
attrView = new AttributeView()
attrView.render();
Run Code Online (Sandbox Code Playgroud)
上面的最后两行不会重新创建视图,因为id ="attrs"的div不再存在.