【问题标题】:jQuery sortable for separated sectionsjQuery可对分隔部分进行排序
【发布时间】:2011-01-27 16:14:38
【问题描述】:

我有主要类别和子类别。 我希望能够在显示如下时对子类别进行排序:

Main Cat1  
  sub cat11            [handle]
  sub cat12            [<>]
  sub cat13            [<>]
Main Cat2
  sub cat21            [<>]
  sub cat22            [<>]
  sub cat23            [<>]

这变成了 HTML

<ul id="order-list-1" class="c_order_list"> 
                    <li id="listItem-2" style=" margin-top:10px;">Sculpture<div style="float:right" align="right"><img src="images/add.png" style="vertical-align:middle; margin-bottom:2px;" onclick="showSubcategoryAddBox(2)"></div></li> 
                                        <li id="subcat-4" style="padding-left: 25px; width: 555px;">subcat1 Of maincat2<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
                                        <li id="subcat-5" style="padding-left: 25px; width: 555px;">subcat2 Of maincat2<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
</ul> 
<ul id="order-list-2" class="c_order_list"> 
                    <li id="listItem-1" style=" margin-top:10px;">Mantel Clocks<div style="float:right" align="right"><img src="images/add.png" style="vertical-align:middle; margin-bottom:2px;" onclick="showSubcategoryAddBox(1)"></div></li> 
                                        <li id="subcat-1" style="padding-left: 25px; width: 555px;">subcat1 Mantel Clocks<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
                                        <li id="subcat-2" style="padding-left: 25px; width: 555px;">subcat2 Mantel Clocks<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
                                        <li id="subcat-3" style="padding-left: 25px; width: 555px;">subcat3 Mantel Clocks<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
</ul> 

我可以只处理一个部分,例如:对主要猫进行排序

$(document).ready(function() {
    var order = null;
    $("#order-list").load(location.href+" #order-list>*","");   
    $("#order-list").sortable({
      handle : '.handle',
      update : function (e, ui) {
             order = $(this).sortable('serialize');
         $("#info").load("process-sortable.php?"+order);
    }
    });

但不知道如何对他们部分中的子类别进行排序?

【问题讨论】:

    标签: jquery html jquery-ui-sortable


    【解决方案1】:

    您的 HTML 中有一个地方需要修复,您的子类别需要自己的

      标签。您的 HTML 应遵循以下类似内容:
      <ul id="main-cats">
       <li><span class="main-cat-handle">Main Cat 1</span>
        <ul id="main-cat-1">
         <li id="sub-cat-1"><span class="sub-cat-handle">Sub Cat 1</span></li>
         <li id="sub-cat-2"><span class="sub-cat-handle">Sub Cat 2</span></li>
         <li id="sub-cat-3"><span class="sub-cat-handle">Sub Cat 3</span></li>
        </ul&gt
       </li>
      </ul>

      现在您应该能够使用指定的句柄在 #main-cats#main-cat-X 上调用 sortable,这应该允许您按照您想要的方式进行排序。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-04
        • 2011-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-16
        • 2021-03-05
        相关资源
        最近更新 更多