我從服務器獲取的數據中的每個10秒,在此,我得到3類型的數據的,無法刪除元素仍然陣列得到清除
超時呼叫後,我除去現有的數據,我可以見證控制檯顯示數組清除,但元素仍然附加。
如何清除DOM中的這兩個元素解除綁定以及..
我關閉函數不斷調用,但沒有元素從DOM中刪除。
我的單一視圖:
singleton.view = Backbone.View.extend({
tagName :'article',
template0 : function(value){
var label = value === 0 ? "projectName" : value === 1 ? "assignedTo" :"projectName";
return _.template("<a href='#'><%= "+label+" %></a>");
},
template1 : _.template($('#boardTemplate').html()),
initialize :function(prams){
this.template = this['template'+0](prams.subTempNo);
},
close:function(){
console.log('clean up') // i am getting consoled
this.unbind();// i am unbinding
this.remove();// i am removing
},
render:function(){
var temp = this.template;
this.$el.html(temp(this.model.toJSON()));
return this;
}
});
return singleton.view;
的意見
:
listViewAppender:function(item,i){
var listElement = new singleton.view({model:item,tempNo:0,subTempNo:i,tagName:'li'});
listElement.close(); // whenever i call the new instance i am removing old stuff..
this.$el.find('.'+this.classItems[i]).append(listElement.render().el);
},
我怎樣才能解決這個問題..任何正確的做法pelase ..
當然,讓我試試這種方式。 – 3gwebtrain
我得到這個錯誤:TypeError:this.listCatch [i] .remove不是函數 – 3gwebtrain
編輯了一下代碼。我假設列表視圖Appender之前調用listViewSet,否則將沒有什麼可以清除。如果首先調用listViewSet,則只需將for循環包裝在檢查'l'(數組長度)大於0的if語句中。同時我添加了兩個控制檯日誌來檢查this.listCatch [i]始終是一個主幹查看 – Xerri