Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在两个列表中以一种方式更好地对JQuery UI进行排序_Jquery_Jquery Ui_Draggable_Jquery Ui Sortable - Fatal编程技术网

如何在两个列表中以一种方式更好地对JQuery UI进行排序

如何在两个列表中以一种方式更好地对JQuery UI进行排序,jquery,jquery-ui,draggable,jquery-ui-sortable,Jquery,Jquery Ui,Draggable,Jquery Ui Sortable,我有两个可排序的项目列表,并相互连接。 一个列表是数据库调用中的所有项AllGroup 另一个是我必须添加的项目列表,调用InGroup 我想可以将项目从AllGroup拖动到InGroup并克隆它,但不能将项目从InGroup拖动到AllGroup。 我的代码: Html: 你怎么能做到?我尝试了一些代码,但没有成功 $('.sort-group').sortable({ connectWith: "#sortable2", tolerance: 'pointer', });

我有两个可排序的项目列表,并相互连接。 一个列表是数据库调用中的所有项
AllGroup
另一个是我必须添加的项目列表,调用
InGroup
我想可以将项目从
AllGroup
拖动到
InGroup
并克隆它,但不能将项目从
InGroup
拖动到
AllGroup
。 我的代码:

Html:

你怎么能做到?我尝试了一些代码,但没有成功

$('.sort-group').sortable({
    connectWith: "#sortable2",
    tolerance: 'pointer',
});

$('#sortable1').bind('sortstop', function(event, ui) {
    var elm = $(ui.item[0]);
    var parent = elm.parent();
    if (!parent.is("#sortable1")) {
        var idx = parent.children().index(elm)-1,
            elm = elm.clone(true);
        parent.children(':eq('+idx+')').after(elm);
    }
    $(this).sortable('cancel');
});
您可以看看它是如何工作的:

$( ".sort-group" ).sortable({
connectWith: ".connectedSortable"
}).disableSelection();
});
$('#sortable1').sortable({ 
    helper: 'clone'
});
$('#sortable1').disableSelection();
$('.sort-group').sortable({
    connectWith: "#sortable2",
    tolerance: 'pointer',
});

$('#sortable1').bind('sortstop', function(event, ui) {
    var elm = $(ui.item[0]);
    var parent = elm.parent();
    if (!parent.is("#sortable1")) {
        var idx = parent.children().index(elm)-1,
            elm = elm.clone(true);
        parent.children(':eq('+idx+')').after(elm);
    }
    $(this).sortable('cancel');
});