Tablesorter n 未定义

我遇到了tablesorter的问题。 错误是:n [0]未定义

function appendToTable(table,cache) { if(table.config.debug) {var appendTime = new Date()} var c = cache, r = c.row, n= c.normalized, totalRows = n.length, checkCell = (n[0].length-1), tableBody = $(table.tBodies[0]), rows = []; for (var i=0;i < totalRows; i++) { rows.push(r[n[i][checkCell]]); if(!table.config.appender) { var o = r[n[i][checkCell]]; var l = o.length; for(var j=0; j < l; j++) { tableBody[0].appendChild(o[j]); } //tableBody.append(r[n[i][checkCell]]); } } 

上面是jquery.tablesorter.js的代码片段。它表示checkCell =(n [0] .length – 1)的行是发生错误的地方。

我不明白如何将未定义的对象传递给函数。 在我的一个项目中,tablesorter工作得很好但在这个项目上没有正常工作。

[编辑]这是用于调用tablesorter的代码片段。 如果我注释掉tablesorter和tablesorterPager,我的代码中没有其他内容会中断。

 $reviewTable = $("#reviewTable"); $reviewTable.tablesorter(); $reviewTable.tablesorterPager({ container: $("#pager"), size: 100, widgets: ['zebra'] }); 

以下是客户端

   
Review ID Date Submitted Rating Image ProductId Status Name
<asp:Label ID="lblEmpty" Text="No Items." runat="server" Visible=''>

如果我记得,你得到的错误是因为表最初是空的(tbody)。 所以修改这行代码:

 checkCell = (n[0].length-1), 

对此:

 checkCell = totalRows ? (n[0].length - 1) : 0, 

如果你有兴趣,我已经分叉并添加了许多增强function(包括上面的更改)到github上的原始tablesorter插件。