【问题标题】:jQuery sortable with serialize on a tablejQuery 可在表上进行序列化排序
【发布时间】:2012-03-15 17:21:17
【问题描述】:

我有一张桌子:

<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>

当我使用“可排序”和默认所有内容时,一切都很好:

jQuery('table.products tbody').sortable();

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

jQuery('table.products tbody').sortable('serialize');

我做错了什么?

【问题讨论】:

  • 你两个都做吗?先用.sortable()初始化,然后用.sortable('serialize')调用方法?如果你只做第二个,插件将不会初始化,实际上什么也不会发生。
  • 现在我只是觉得很傻。我现在不能接受评论作为答案吗?
  • 不,你不能,我已经发布了答案;-)
  • 否;但你可以投票给月球,我也可以!

标签: jquery jquery-ui jquery-ui-sortable


【解决方案1】:

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

您必须先使用.sortable() 初始化插件,然后才能调用.sortable('serialize') 等方法。

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

$table.sortable();
$table.sortable('serialize');

【讨论】:

  • 链接此方法以减少开销。 $("element").sortable().sortable('serialize');
  • @Ohgodwhy。是的,你可以(应该)链接,为了这个例子,我做了两个陈述。
  • 是的。我仍然肯定赞成。只需添加那些 2cp 以获得最佳实践:)
猜你喜欢
  • 1970-01-01
  • 2010-12-29
  • 2014-06-21
  • 1970-01-01
  • 2017-02-20
  • 1970-01-01
  • 2014-09-14
  • 1970-01-01
  • 2010-11-01
相关资源
最近更新 更多