0
我想從我的應用程序中的itemDataSource中刪除所有項目。 itemDataSource被綁定到一個列表視圖。爲什麼不清除這個itemDataSource?
我已經成功地刪除時,它的點擊在列表視圖中的單個項目,但刪除所有項目引起了我的問題:(
這是我以前從itemDataSource刪除單個項目的代碼:
//remove the clicked playlist item
var ds = document.getElementById("PlaylistListView").winControl.itemDataSource;
ds.beginEdits();
ds.remove(ds.itemFromIndex(eventInfo.detail.itemPromise._value.index)._value.key);
ds.endEdits();
這是我一直試圖寫入刪除所有項目代碼:
var ds = document.getElementById("PlaylistListView").winControl.itemDataSource;
ds.beginEdits();
console.log(ds._list._keys);
console.log("There are " + ds._list._keys.length + " items in this list");
for (var i = 0; i < ds._list._keys.length; i++) {
ds.remove(ds._list._keys[i]);
console.log("Item: " + ds._list._keys[i] + " has been removed from the list");
}
ds.endEdits();
這是我收到的控制檯輸出,當我運行這款C頌:
1,2,3,4,5,6,7,8,9,10,11
There are 11 items in this list
Item: 2 has been removed from the list
Item: 4 has been removed from the list
Item: 6 has been removed from the list
Item: 8 has been removed from the list
Item: 10 has been removed from the list
Item: undefined has been removed from the list
爲什麼只被刪除一些項目?輸出如預期的那樣,但是導致項目1,3,5,7,9, and 11
不能被刪除的原因是什麼?我注意到序列中有一個模式,每次都是2。
任何幫助,將不勝感激:)