问题描述
我想使用jQuery Plugin TableSorter对我的表进行排序.所以我得到这张桌子:
i wanna sort my table with jQuery Plugin TableSorter . So i get this table :
<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>
因此您可以看到我的表是空的,只有标题.所以我用空单元格初始化tablesorter:
So as you can see my table is empty, just had header. So i init tablesorter with empty cell with :
$("table#stats").tablesorter({ sortList: [[0,0]]});
我立即收到此错误:
jquery.tablesorter.min.js:4 Uncaught TypeError: Cannot read property '0' of undefined
仅供参考,我的js已加载:
FYI , there's my js loaded :
<!-- 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>
有什么主意为什么得到这个以及如何使插件再次工作?
Any idea why i get this and how i can make the plugin work again ?
Thx
推荐答案
您需要先在表中包含数据,然后才能在其上调用sortList方法.这是因为您在此方法中应用了索引,如果不存在数据,该索引将找不到任何记录,并且将引发无法读取未定义的属性'0'"错误.
You need to have data in your table before you can call the sortList method on it. This is because you apply an indexing in this method that will not find any records if there is no data present and that will throw the "Cannot read property '0' of undefined" error.
这篇关于初始化时出现jQuery TableSorter插件错误:无法读取未定义的属性"0"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!