我不知道为什么这个可排序函数不能给出我想要的结果,即在我的可排序列表中抓取和删除选定的多个元素。
我的代码如下:
setUsersList() {
$('ul').on('click', 'li', function (e) {
if (e.ctrlKey || e.metaKey) {
$(this).toggleClass("selected");
} else {
$(this).addClass("selected").siblings().removeClass('selected');
}
});
$('.users-list').sortable({
items: "li:not(.to-resize)",
connectWith: '.users-list',
placeholder: 'placeholder',
helper: function (e, item) {
var elements = item.parent().children('.selected:not(.to-resize)').clone(); //there are other elements in between which I don't want to select, that's why I'm using 'not' selector, elements gives the proper and desired output of all selected items
item.data('multidrag', elements).siblings('.selected').remove();
var helper = $('<li/>');
return helper.append(elements);
},
stop: function (e, ui) {
var elements = ui.item.data('multidrag');
ui.item.after(elements);
}
});
$('.users-list').disableSelection();
}
当我删除多个选定项时,我正在复制其中一个项(例如,第一个项按预期删除,第二个项复制)。如何修复它?