On JQuery UI do one draggable connectToSortable multiple sortables

三世轮回 提交于 2020-01-24 21:51:03

问题


In JQuery UI, I have a draggable, It have an option connectToSortable as below:

$("#social li").draggable({
       connectToSortable: '#form_builder_sortable',
       helper:'clone',
       revert:true
 });

'#form_builder_sortable' is a sortable as below:

$("#form_builder_sortable").sortable();

I want 1 draggable list connect to multiple sortable list, such as:

$("#social li").draggable(
{
    connectToSortable: '#form_builder_sortable, #form_builder_sortable_sample',
       helper:'clone',
       revert:true
 });

Have you got any solutions or suggestion to do as my requirement? Thanks a lot


回答1:


The connectToSortable option accepts a selector and a selector can specify any number of lists.

Please see following example:

Draggable list

<ul>
    <li class="draggable ui-state-highlight">Drag me down</li>
</ul>

Mulitiple list

<ul id="form_builder_sortable" class="sortable">
    <li class="ui-state-default draggable">Item 1</li>
    <li class="ui-state-default draggable">Item 2</li>
    <li class="ui-state-default draggable">Item 3</li>
</ul>

<ul id="form_builder_sortable_sample" class="sortable">
    <li class="ui-state-default draggable">Item 1</li>
    <li class="ui-state-default draggable">Item 2</li>
    <li class="ui-state-default draggable">Item 3</li>
    <li class="ui-state-default draggable">Item 4</li>
</ul>

I gave them same class class="sortable" because I want drag draggable list to both of them. Finally I can use code below for drag it:

$(".sortable").sortable();

$(".draggable").draggable({
  connectToSortable: '.sortable', // Selector selects lists that have sortable class
  helper: 'clone'
});

Online demo (fiddle)



来源:https://stackoverflow.com/questions/46590926/on-jquery-ui-do-one-draggable-connecttosortable-multiple-sortables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!