我有表格,在通过 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/