jquery sortable - 防止2个列表之间的重复

Gre*_*reg 4 jquery jquery-ui-sortable

如在标题中,我如何防止2个列表之间的重复.我试图在#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);
            }
        })
    });
});
Run Code Online (Sandbox Code Playgroud)

Gre*_*reg 8

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

 $("#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();
            }
        },
    });
Run Code Online (Sandbox Code Playgroud)