简体   繁体   English

jQuery:追加子项+可排序

[英]jQuery : Append child + sortable

I need to sort some li 's but I don't know how to add a children to an empty li . 我需要对一些li进行排序,但是我不知道如何为空li添加孩子。 At this moment I can add li 's to another li only if is not empty. 此时,仅当不为空时,我才能将li添加到另一个li

EG. 例如。

<ul>
     <li id="1">Item</li>
     <li id="2">Item
         <ul>
            <li id="3">Item</li>
            <li id="4">Item</li>
         </ul>
     </li>
     <li id="5">Item</li>
     <li id="6">Item</li>
</ul>

So I can add li_1 into li_2 but I can't add li_6 into li_5 because li_5 is empty. 所以我可以将li_1添加到li_2中,但是不能将li_6添加到li_5中,因为li_5为空。

My work can be found here . 我的工作可以在这里找到。

A simple solution is to add empty ul with an padding / margin than you can drop the items into this empty sublist. 一个简单的解决方案是添加一个带填充/边距的空ul,然后再将这些项目放到该空子列表中。 http://jsfiddle.net/k83QH/2/ http://jsfiddle.net/k83QH/2/

One way to get around this would be to add an empty ul, in jQuery, to any list items that could potential have children dragged into them. 解决此问题的一种方法是在jQuery中向任何可能将子级拖入其中的列表项中添加一个空ul。 That way you'll get the drop container for all of your li's 这样一来,您将得到李先生所有的托运容器

您将必须检查该li是否有ul子元素,如果没有,则添加ul元素,然后在其中添加子li元素。

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

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