我正在尝试从我的应用程序中的 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();
这是我在运行此代码时在控制台中得到的输出:
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。
任何帮助将不胜感激 :)