简体   繁体   English

jQuery UI Sortable-嵌套Sortable Divs connectWith

[英]JQuery UI Sortable - Nested Sortable Divs connectWith

I'm using JQuery UI Sortable to try to have a group of sortable divs, which could also potentially be divs that have sortable applied to them. 我正在使用JQuery UI Sortable尝试具有一组可排序的div,也可能是已对其应用了可排序的div。 And these sortables should be able to move items between each other. 这些可排序对象应该能够在彼此之间移动项目。

I'm able to get items in the parent sortable div to the children sortable divs, but I can't get the items from the children back to the parents. 我能够将父项可排序div中的项目获取给子项可排序div,但是我无法将项从子项中返回给父级。

Is this possible? 这可能吗?

<div id="block-container">
  <div class="block">block1</div>
  <div class="sub-wrapper">
    <div class="block-sub-container">
      <div class="block"></div>
      <div class="block"></div>
    </div>
  </div>   
</div>


$('#block-container').sortable({connectWith: ".block-sub-container"});
$('.block-sub-container').sortable({connectWith: "#block-container"});

Here is what I'm working with: http://jsfiddle.net/5pm24/ 这是我正在使用的工具: http : //jsfiddle.net/5pm24/

You can see that outside items can be dragged into the black boxes, but once they are there they cannot be brought back out. 您可以看到外部项目可以拖到黑盒中,但是一旦到达那里就无法将它们带出。

I want to get a .block from .block-sub-container to move directly under #block-container. 我想从.block-sub-container获取一个.block,使其直接移动到#block-container下。

In fact it works fine, however you set float:left for the .block causing the parent #block-container shrink to empty size . 实际上,它工作正常,但是您为.block设置了float:left ,导致父#block-container 缩小为空尺寸 Because you did not set explicit size for the parent. 因为您没有为父级设置显式尺寸。 If you don't want to set explicit size, I think you can set the overflow:auto for it and the problem will be solved. 如果您不想设置显式的大小,我想您可以为其设置overflow:auto ,问题将得到解决。

#block-container {
  /* set border to see its boundary */
  border:1px solid black;
  overflow:auto;
}

Demo. 演示

Although the overflow:auto helps showing the border to wrap all the contents but looks like sometimes the drag and drop does not work expectedly when you drop the item inside the border bounds. 尽管overflow:auto可以帮助显示边框来包装所有内容,但是当您将项目放在边框内时,有时拖放似乎无法正常进行。 The best solution is fixing the size of the container, it also prevent flickering while dragging and dropping. 最好的解决方案是固定容器的尺寸,还可以防止在拖放过程中闪烁。 Test this demo to see the difference. 测试此演示以了解差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM