简体   繁体   English

如何使jQuery UI可排序容器中的元素可自由拖动?

[英]how can I make the elements in a jQuery UI sortable container be freely draggable?

Basically, I want to be able to freely drag items in a container and leave them at whatever position I desire.. However, if there are two items touching each other, dragging the one on the right towards the one on the left should cause the two to swap positions (hence sortability)... 基本上,我希望能够自由拖动容器中的项目并将它们放置在所需的任何位置。.但是,如果有两个项目彼此接触,则将右侧的项目拖向左侧的项目会导致两个交换位置(因此可排序)...

However, if I do: 但是,如果我这样做:

container.sortable({axis: 'x'});
item_1.draggable({axis: 'x'});
item_2.draggable({axis: 'x'});
container.append(item_1);
container.append(item_2);

then they are not sortable, just draggable... How can I accomplish this? 那么它们就不能排序,只能拖动...我该如何完成?

Have you tried using the refresh method? 您是否尝试过使用refresh方法?

Refresh the sortable items. 刷新可排序项目。 Custom trigger the reloading of all sortable items, causing new items to be recognized. 自定义触发所有可排序项目的重新加载,从而导致新项目被识别。

This should be called after you append the new elements. 附加新元素后应调用此方法。

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

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