簡體   English   中英

jQuery Sortable wit未定義列表數

[英]Jquery Sortable wit undefined number of lists

我有一個正在從數據庫中檢索的列表。 列表的數目是不確定的,因為它們來自數據庫。 這些列表可以拖動到其他列表。 這是代碼

<?php while(..condition..){ ?>
<ul id="test-list-sub<?=$x?>" class="connectedSortable2" style="padding-bottom:10px;">
  <li id="listItemSub_<?=$row['id']?>">
    <table>...content here...</table>
  </li>
</ul>
<?php $x++; } //end while ?>

Java腳本

for(var y=0; y<<?=$x?>; y++){

    $("#test-list-sub"+y).sortable({
      handle : '.handle',
      connectWith: ".connectedSortable2",
      update : function () {
          var order = $("#test-list-sub"+y).sortable('serialize');
          alert(order);
        //$("#info2").load("process-sortable.php?"+order+"&panel=2");
      }
    });

}

此過程有效,但是問題是當我嘗試獲取列表項時,我得到了[Object] [object],但是當我嘗試更改

var order = $("#test-list-sub"+y).sortable('serialize');

var order = $("#test-list-sub0").sortable('serialize'); //or any number 0-number of lists

我得到了價值。 似乎在sortable的“更新”部分傳遞的“值y”是y的最后一個值。 我應該怎么做才能從清單中獲得價值?

找到了答案

$('.connectedSortable2').each(function() {
        var pid = $(this).attr('id').split('_')[1];
        $("#test-list-sub_"+pid).sortable({
          handle : '.handle',
          connectWith: ".connectedSortable2",
          update : function () {
              var order = $("#test-list-sub_"+pid).sortable('serialize');
              alert(order);
            //$("#info2").load("process-sortable.php?"+order+"&panel=2");
          }
        });
    });

我使用了每個函數來獲取它們。 由於他們有相同的階級。 答案來自jquery可排序>嵌套uls

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM