javascript - jQuery 表格排序器 : TypeError: s[1] is undefined

标签 javascript jquery tablesorter

我有表格,在通过 JS 更新它之后我运行更新触发器(就像在这种情况下多次提到的那样)但是它不起作用并且 FireBug 说:“TypeError: s[1] is undefined”。

// in $(document).ready()
$('#stattable').tablesorter();

// after updating table content
$('#stattable').triggerHandler('update');
$('#stattable').trigger('sorton', [[1, 1], [0, 0]]);
$('#stattable').trigger('appendCache');

HTML代码:

<table id="stattable">
 <thead>
  <tr><th>Producer</th><th>Value</th><th>Amount</th></tr>
 </thead>
 <tbody>
  <!-- here dynamically generated data -->
 </tbody>
 <tfoot>
  <tr><td>SUM:</td><td></td><td></td></tr>
 </tfoot> 
</table>

动态数据格式:

<tr>
 <td>Ford</td>
 <td>1999.90</td>
 <td>10</td>
</tr>
<tr>
 <td>Renault</td>
 <td>345.1</td>
 <td>2</td>
</tr>
<tr>
 <td>Mitsubishi</td>
 <td>0</td>
 <td>0</td>
</tr>
... etc.

有什么想法吗?

最佳答案

当你trigger一个事件,您需要将额外的参数括在方括号中:

$('selector').trigger('event', [ parameters ]);

所以在这种情况下,sortList 缺少一组额外的括号:

$('#stattable').trigger('sorton', [ [[1, 1], [0, 0]] ]);

关于javascript - jQuery 表格排序器 : TypeError: s[1] is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756187/

相关文章:

javascript - Dynamics CRM 2016 Online - 使用对话框后刷新记录

javascript - 为什么这个点击事件失败

jQuery:如何从 $.ajax.error 方法中获取 HTTP 状态代码?

javascript - JQuery tablesorter,<table> in <table>(嵌套表)

javascript 表排序/分页(客户端)。多大算太大?

javascript - 在表格排序器搜索功能上仅显示一个结果

Javascript - 将过滤器应用于 Canvas 并重置为原始值

javascript - puppeteer 师无限滚动

javascript - 鼠标悬停时显示框

javascript - 如何在延迟后在一个 div 中显示消息队列?