我想使用 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/