gpt4 book ai didi

jquery sortable - 防止两个列表之间出现重复

转载 作者:行者123 更新时间:2023-12-01 00:00:06 24 4
gpt4 key购买 nike

如标题所示,如何防止两个列表之间出现重复。我正在尝试停止 #selected 列表中的重复项。我怀疑它是在接收事件中完成的,但我没有任何运气。

    $(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);
}
})
});
});

最佳答案

终于解决了。当你看到解决方案时有点明显。可能还有其他方法可以做到这一点。

 $("#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 sortable - 防止两个列表之间出现重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15668524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com