【问题标题】:jQuery plugin tablesorter jSON: o is undefinedjQuery 插件 tablesorter jSON: o 未定义
【发布时间】:2011-09-21 16:24:17
【问题描述】:

我有一个存储一些数据的表。此数据从 code.php 以 JSON 结构的数组返回。

    $("#errtable").tablesorter(); 
 $.getJSON("./include/code.php",  {key:$('#key').val()}, function(data) { 
     // append the "ajax'd" data to the table body 
  $.each(data, function(key) {
    $("#errtable > tbody").append("<tr><td>"+data[key].errorcode+"</td><td>"+data[key].errordescription+"</td></tr>");
  }); 
    // let the plugin know that we made a update 
    $("#errtable").trigger("update"); 
    // set sorting column and direction, this will sort on the first and third column 
    var sorting = [[2,1],[0,0]]; 
    // sort on the first column 
    $("#errtable").trigger("sorton",[sorting]); 
});

问题是Firebug显示错误:

o 未定义 [Break On This Error] o.count = s[1];

指:

    function updateHeaderSortCount(table, sortList) {
        var c = table.config,
            l = sortList.length;
        for (var i = 0; i < l; i++) {
            var s = sortList[i],
                o = c.headerList[s[0]];
            o.count = s[1];
            o.count++;
        }
    }

有人可以帮我解决这个问题吗?

谢谢。

【问题讨论】:

    标签: php javascript jquery jquery-plugins


    【解决方案1】:

    如果我没记错的话,您可以使用以下代码每行插入两个单元格:

    $("#errtable > tbody").append("<tr><td>"+data[key].errorcode+"</td><td>"+data[key].errordescription+"</td></tr>");
    

    并尝试对不存在的第三列进行两次排序:

    // set sorting column and direction, this will sort on the first and third column 
    var sorting = [[2,1],[0,0]]; 
    

    在我看来,对第二个和第一个排序——而不是第三个——应该可以解决这个错误

    【讨论】:

    • 你有例子吗?我刚刚放了 $("#errtable").trigger("update");无需对 var 进行排序,它就可以工作。
    • 正如我所提到的,问题是试图对不存在的列进行排序。如果我不认为是错误的,这应该可以工作:var sorting = [[1,1],[0,0]];您能否提供您的应用程序或 jsfiddle 的演示?
    猜你喜欢
    • 1970-01-01
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多