【问题标题】:Jquery Sortable wit undefined number of listsJquery Sortable wit undefined number of lists
【发布时间】:2012-11-15 05:24:58
【问题描述】:

我有一个正在从数据库中检索的列表。 列表的数量未定义,因为它们来自数据库。 这些列表可以拖到其他列表中。 这是代码

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

}

这个过程有效,但问题是当我尝试获取我得到的列表项时 [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 的最后一个值。我应该怎么做才能从列表中获取值?

【问题讨论】:

    标签: php javascript jquery jquery-ui-sortable


    【解决方案1】:

    找到答案

    $('.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 函数来获取它们。因为他们上的是同一堂课。 答案来自jquery sortable > nested uls

    【讨论】:

      猜你喜欢
      • 2022-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 2022-12-02
      • 1970-01-01
      相关资源
      最近更新 更多