如何包含要使用 MooTools 的 Sortable 插件拖动的 DOM 元素的所有子元素?
我正在使用 mootools-more.1817.js
...这是我的 HTML 结构:
<ul id="categories">
<div id="admin">Admin Controls</div>
<li class="selected"><a href="#">Test</a>
<ul>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Test 2</a>
<ul>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Top Links</a>
<ul>
<li id="article"><a href="/1">Link 1</a></li>
<li id="article"><a href="/3">Link 2</a></li>
<li id="article"><a href="/2">Link 3</a></li>
<li id="article"><a href="/4">Link 4</a></li>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Lame Links</a>
<ul>
<li id="article"><a href="/9">Link 9</a></li>
<li id="article"><a href="/10">Link 10</a></li>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Awesome Links</a>
<ul>
<li id="article"><a href="/11">Link 11</a></li>
<li id="article"><a href="/12">Link 12</a></li>
</ul>
</li>
</ul>
所以我想做两件事:
- 能够将每个
li
项目拖动到另一个项目部分并让它带着所有的孩子。例如,如果我拖动具有链接Top Links
的 li,我不仅要拖动单词Top Links
,还要拖动div#admin、
ul
和li
是该父级li
的子级。本质上是每个li
的所有子级。 - 我还希望能够在孩子列表之间拖动项目。举例来说,假设我想将链接
Link 2
从该ul
拖到名为Awesome Links
的部分,并将其放在链接 <代码>链接11和链接12
。
我已经这样做了:
window.addEvent('domready', function(){
new Sortables('#categories', {
clone: true,
revert: true,
opacity: 0.7
});
});
它所做的只是拖动 li
,而不是 li
的子级。
我如何实现这些目标?
谢谢。
I am using mootools-more.1817.js
...this is my HTML structure:
<ul id="categories">
<div id="admin">Admin Controls</div>
<li class="selected"><a href="#">Test</a>
<ul>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Test 2</a>
<ul>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Top Links</a>
<ul>
<li id="article"><a href="/1">Link 1</a></li>
<li id="article"><a href="/3">Link 2</a></li>
<li id="article"><a href="/2">Link 3</a></li>
<li id="article"><a href="/4">Link 4</a></li>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Lame Links</a>
<ul>
<li id="article"><a href="/9">Link 9</a></li>
<li id="article"><a href="/10">Link 10</a></li>
</ul>
</li>
<div id="admin">Admin Controls</div>
<li><a href="#">Awesome Links</a>
<ul>
<li id="article"><a href="/11">Link 11</a></li>
<li id="article"><a href="/12">Link 12</a></li>
</ul>
</li>
</ul>
So I want to do two things:
- Be able to drag each
li
item to another section and have it take all its children with it. E.g. if I am dragging the li that has the linkTop Links
, I want to drag not only the wordsTop Links
, but also thediv#admin
,ul
andli
that are children of that parentli
. Essentially all the children of eachli
. - I would also like to be able to drag items between lists of the children. So for instance, say I want to drag the link
Link 2
from thatul
to the section calledAwesome Links
and drop it between the linksLink 11
andLink 12
.
I have done this:
window.addEvent('domready', function(){
new Sortables('#categories', {
clone: true,
revert: true,
opacity: 0.7
});
});
What that does is drags JUST the li
, and not the children of the li
.
How do I achieve those?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,由于
categories
列表中的div
项不在li
标记本身中,因此您的 HTML 无效。对于有效列表,ul
的唯一直接子级可以是li
。其次,根据文档,“要启用列表之间的排序,必须使用数组或选择器传递一个或多个列表或 id”(http://mootools.net/docs/more/Drag/Sortables)。这意味着,要在子列表之间移动项目,每个
ul
必须传递到可排序组(与类别组不同)。这应该可以解决您的问题#2。我还不确定为什么它不会拖动
li
的全部内容,尽管可能是无效的 HTML 导致了问题。First, you have invalid HTML by having
div
items in yourcategories
list that are not inli
tags themselves. The only immediate children to aul
can beli
for a valid list.Second, according to the documentation, "To enable sorting between lists, one or more lists or id's must be passed using an array or a selector" (http://mootools.net/docs/more/Drag/Sortables). That means, to move items between your sublists, each
ul
must be passed into a sortables group (different than the categories group). This should solve your issue #2.I'm not yet sure why it would not drag the whole contents of the
li
, though it may be the invalid HTML is causing issues.