jQuery可排序-防止2个列表之间重复 [英] jquery sortable - prevent duplicates between 2 lists
本文介绍了jQuery可排序-防止2个列表之间重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如标题中所示,如何防止2个列表之间重复.我正在尝试在#selected列表中停止重复项.我怀疑它是在接收事件中完成的,但是我没有任何运气.
as in the title, how can I prevent duplicates between 2 lists. I am trying to stop duplicates in the #selected list. I suspect its done in the receive event but i am not having any luck.
$(function () {
$("#options").sortable({
connectWith: $("#selected"),
helper: 'original',
revert: true,
tolerance: "pointer",
});
$("#selected").sortable({
connectWith: $("#options"),
helper: 'original',
receive: function (event, ui) {
},
});
$("#options,#selected").disableSelection();
$("#SkillGroups").change(function () {
$.ajax({
type: "POST",
url: "/Contractor/Contractor/GetSkillsBySkillGroup",
data: { skillGroupId: $("#SkillGroups").val() },
success: function (result) {
$loadList(result);
}
})
});
});
推荐答案
终于解决了.当您看到解决方案时,这有点明显.可能还有其他方法可以做到这一点.
Finally worked it out. A bit obvious when you see the solution. There are probably other ways to do this as well.
$("#selected").sortable({
connectWith: $("#options"),
helper: 'original',
receive: function (event, ui) {
var identicalItemCount = $("#selected").children('li:contains(' + ui.item.text() + ')').length;
alert(identicalItemCount);
if (identicalItemCount > 1) {
alert("Ahem.... we have a duplicate!!");
$("#selected").children('li:contains(' + ui.item.text() + ')').first().remove();
}
},
});
这篇关于jQuery可排序-防止2个列表之间重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文