jQuery TableSorter 插件初始化时出现错误 : cannot read property '0' of undefined

标签 jquery jquery-plugins tablesorter

我想使用 jQuery 插件 TableSorter 对我的表格进行排序。所以我得到了这张表:

<table id="stats" class="zebra-striped">
 <thead>
  <tr>
   <th>Date</th>
   <th>Annonce</th>
   <th>Support</th>
   <th>Nb Assoc.</th>
   <th>Nb Transfo.</th>
   <th>Cout</th>
  </tr>
 </thead>
 <tbody>
 </tbody>
</table>

正如你所看到的,我的表格是空的,只有标题。所以我用空单元格初始化表格排序器:

$("table#stats").tablesorter({ sortList: [[0,0]]});

我立即收到此错误:

jquery.tablesorter.min.js:4 未捕获的类型错误:无法读取未定义的属性“0”

仅供引用,我的 js 已加载:

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>
<script src="js/bootstrap-dropdown.js"></script>
<script src="js/bootstrap-scrollspy.js"></script>
<script src="js/jquery.tablesorter.min.js"></script>

知道为什么我会得到这个以及如何让插件再次工作吗?

谢谢

最佳答案

您的表中需要有数据,然后才能对其调用 sortList 方法。这是因为您在此方法中应用索引,如果不存在数据,则不会找到任何记录,并且会抛出“无法读取未定义的属性‘0’”错误。

关于jQuery TableSorter 插件初始化时出现错误 : cannot read property '0' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8878945/

相关文章:

c# - jQuery如何在删除属性之前检查属性是否存在

javascript - Ajax 邮政 302 : Variable more than 1MB giving 302 redirect by Controller

javascript - 将元素符号控件添加到选项卡式幻灯片

jquery - offset().left 返回奇怪的值

class - 将类添加到 TableSorter 过滤器小部件输入?

javascript - Tablesorter 嵌套表 - 子行(由用户按需创建)不与父行一起排序

php - 在 slider 图像上溢出隐藏边框

jquery - flot - 显示没有间隙的时间轴

javascript - jQuery 可选择并禁用选定表格单元格中的输入

javascript - Tablesorter Filter 小部件在所有浏览器上更新后停止工作,没有错误消息