如何包含要使用 MooTools 的 Sortable 插件拖动的 DOM 元素的所有子元素?

发布于 2024-12-18 16:11:23 字数 2361 浏览 5 评论 0原文

我正在使用 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>

所以我想做两件事:

  1. 能够将每个 li 项目拖动到另一个项目部分并让它带着所有的孩子。例如,如果我拖动具有链接 Top Links 的 li,我不仅要拖动单词 Top Links,还要拖动 div#admin、ulli 是该父级 li 的子级。本质上是每个 li 的所有子级。
  2. 我还希望能够在孩子列表之间拖动项目。举例来说,假设我想将链接 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:

  1. 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 link Top Links, I want to drag not only the words Top Links, but also the div#admin, ul and li that are children of that parent li. Essentially all the children of each li.
  2. 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 that ul to the section called Awesome Links and drop it between the links Link 11 and Link 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶舞 2024-12-25 16:11:23

首先,由于 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 your categories list that are not in li tags themselves. The only immediate children to a ul can be li 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文