2012-11-15 37 views
1

我有一个正在从数据库中检索的列表。 列表的数量是未定义的,因为它们来自数据库。 这些列表可以拖到其他列表。 这里是代码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 ?> 

的Javascript

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"); 
     } 
    }); 

} 

这个过程的作品,但问题是,当我试图让列表项我得到 [对象] [对象]但是当我试图改变在

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

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

我得到的价值。似乎在'可更新'部分中传递的'值y'是y的最后一个值。我应该怎么做才能从列表中获得价值?

回答

0

找到了答案

$('.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 sortable > nested uls