我有一个正在从数据库中检索的列表。 列表的数量未定义,因为它们来自数据库。 这些列表可以拖动到其他列表。 这是代码
<?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
我得到了值(value)。似乎在可排序的“更新”部分中传递的“值 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");
}
});
});
我使用each函数来获取它们。因为他们在同一个类(class)。 答案来自jquery sortable > nested uls
关于php - Jquery 可排序,未定义数量的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391982/