jQuery可以在表上进行序列化排序

Hon*_*ner 4 jquery jquery-ui jquery-ui-sortable

我有一张桌子:

<table class="products">
    <thead>...</thead>
    <tfoot>...</tfoot>

    <tbody id="the-list">
      <tr id="order-0">
        <th scope="row" class="check-column">stuff</th>
        <td class="title column-title">stuff</td>
        <td class="order column-order">stuff</td>
        <td class="display column-display">stuff</td>
        <td class="action column-action">stuff</td>
      </tr>
      <tr id="order-1">
        <th scope="row" class="check-column">stuff</th>
        <td class="title column-title">stuff</td>
        <td class="order column-order">stuff</td>
        <td class="display column-display">stuff</td>
        <td class="action column-action">stuff</td>
      </tr>
      <tr id="order-2">
        <th scope="row" class="check-column">stuff</th>
        <td class="title column-title">stuff</td>
        <td class="order column-order">stuff</td>
        <td class="display column-display">stuff</td>
        <td class="action column-action">stuff</td>
      </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

当我使用"sortable"和默认的一切时,一切都很好:

jQuery('table.products tbody').sortable();
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试序列化时,所有可排序的功能都会消失,表格是静态的(尽管......但没有错误)

jQuery('table.products tbody').sortable('serialize');
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

Did*_*hys 5

从您的问题来看,您似乎没有在尝试使用其中的方法之前初始化您的插件.

你必须首先使用init来启动插件,.sortable()然后你可以调用类似的方法.sortable('serialize').

var $table = jQuery('table.products tbody');

$table.sortable();
$table.sortable('serialize');
Run Code Online (Sandbox Code Playgroud)

  • 链接此方法以减少开销.$( "元件")排序()排序( '序列化').; (2认同)