跨多个容器或父级的 jQuery UI 可排序 div [英] jQuery UI sortable divs across multiple containers or parents
问题描述
我有一个对象列表,该列表分为两个容器,我想通过 jQuery 对其进行排序,但我不知道如何使一个对象能够添加到另一个容器列表中,反之亦然.因此,我希望能够将一个对象从一个容器拖到另一个容器中,并让代码将其视为一个列表.
I have a list of objects that is split into two containers that I want to make sortable via jQuery but I cannot figure out how to make one object able to be added to the other containers list and vice versa. So, I want to be able to drag an object from one container into the other and have the code treat it as if it were one list.
下面是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 1</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery-ui/js/jquery-ui-1.8.22.custom.min.js"</script>
<link type="text/css" href="jquery-ui/css/smoothness/jquery-ui-1.8.22.custom.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function(){
$("#nowplaying_list, #nowplaying_history").sortable().disableSelection();
});
</script>
</head>
<body>
<div id="left_content" class="ui-droppable">
<div id="nowplaying_container" style="display:block;">
<div id="nowplaying_wrapper">
<div id="nowplaying_history" class="ui-sortable">
<div class="object_container ui-draggable" >OBJECT 1</div>
<div class="object_container ui-draggable" >OBJECT 2</div>
<div class="object_container ui-draggable" >OBJECT 3</div>
</div>
<div id="nowplaying_list" class="ui-sortable">
<div class="object_container ui-draggable" >OBJECT 4</div>
<div class="object_container ui-draggable" >OBJECT 5</div>
<div class="object_container ui-draggable" >OBJECT 6</div>
</div>
</div>
</div>
</div>
</body>
</html>
推荐答案
看看 Sortable Portlets 示例,它似乎有你想要的行为.
Take a look at the Sortable Portlets example, it appears to have the behavior you want.
关键是 connectWith
选项,您可以在为两个容器分配一个公共类后使用它:
The key is the connectWith
option, which you could use once you assign a common class to both containers:
$(".now-playing-block").sortable({
connectWith: '.now-playing-block'
});
(为了清楚起见,我省略了链接的 .disableSelection()
调用.)
(I left out the chained .disableSelection()
call for clarity.)
这篇关于跨多个容器或父级的 jQuery UI 可排序 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!