我查看了 Controls_ListViewWorkingWithDataSources MSDN 示例,了解如何从 WinJS.Binding.List 中删除项目,这是他们的解决方案。请告诉我有一个更简单的方法。
if (list2.selection.count() > 0) {
list2.selection.getItems().done(function (items) {
//Sort the selection to ensure its in index order
items.sort(function CompareForSort(item1, item2) {
var first = item1.index, second = item2.index;
if (first === second) {
return 0;
}
else if (first < second) {
return -1;
}
else {
return 1;
}
});
//Work backwards as the removal will affect the indices of subsequent items
for (var j = items.length - 1; j >= 0; j--) {
// To remove the items, call splice on the list, passing in a count and no replacements
lettersList.splice(items[j].index, 1);
}
});