可排序(" toArray")无效

时间:2017-11-24 05:04:17

标签: jquery

我是AJAX / javascript的新手,我完全无能为力,坚持这个问题。

我有一张桌子,我希望通过拖放来排序。我实现了下面提到的代码。这使得表行可以拖动,但我没有得到我应该发送到数据库的ID。

提前感谢您的帮助。



<table id="masterlist" class="table table-striped table-bordered base-style">
  <thead class="bg-grey">
    <tr>
      <th>Field Name</th>
      <th>Created By</th>
      <th>Created On</th>
      <th>Status</th>
      <th></th>
    </tr>
  </thead>
  <tbody id="tb">
    <tr id="sn_1">
      <td>Doctorate</td>
      <td>User</td>
      <td>15th-Sep-17</td>
      <td>
        Active
        <a href="mypage.php?v=12" class="btn-sm btn-danger">Deactivate</a>
      </td>
      <td><a data-toggle="modal" data-target="#edit_" data-backdrop="false" class="btn-sm btn-warning" role="button">Edit</a>
      </td>
    </tr>
    <tr id="sn_2">
      <td>Post Graduate/Diploma Degree</td>
      <td>User</td>
      <td>15th-Sep-17</td>
      <td>
        Active
        <a href="mypage.php?v=12" class="btn-sm btn-danger">Deactivate</a>
      </td>
      <td><a data-toggle="modal" data-target="#edit_" data-backdrop="false" class="btn-sm btn-warning" role="button">Edit</a>
      </td>
    </tr>
    <tr id="sn_3">
      <td>Graduate Degree</td>
      <td>User</td>
      <td>15th-Sep-17</td>
      <td>
        Active
        <a href="mypage.php?v=12" class="btn-sm btn-danger">Deactivate</a>
      </td>
      <td><a data-toggle="modal" data-target="#edit_" data-backdrop="false" class="btn-sm btn-warning" role="button">Edit</a>
      </td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th>Field Name</th>
      <th>Created By</th>
      <th>Created On</th>
      <th>Status</th>
      <th></th>
    </tr>
  </tfoot>
</table>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
  $('#tb').sortable();
  
  $("#tb").sortable({
    stop: function(event, ui) {
      var sortedIDs = $("#tb").sortable("toArray");
      console.log(sortedIDs);
    }
  });
</script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

$(document).ready(function(){
    $('#sortable').sortable({
        update: function(event, ui) {
            var newOrder = $(this).sortable('toArray').toString();
            $.get('saveSortable.php', {order:newOrder});
        }
    });
});