对通过jQuery追加JSON数据的Jquery表进行排序

时间:2015-12-08 05:14:32

标签: javascript jquery html json

我想按照以下顺序对表进行排序。我使用JQuery表来显示JSON数据。我尝试使用tablesorter插件,但我没有配置它。有没有办法对此表进行排序。谢谢你提前。

  1. 失败
  2. 中止
  3. 成功
  4. JSON数据

    {
          "Product":"APIM",
          "Day01":"Success",
          "Day02":"Aborted",
          "Day03":"Failed",
          "Day04":"Failed",
          "Day05":"Failed",
          "Day06":"Failed",
          "Day07":"Success"
       },
       {
          "Product":"AppFactory",
          "Day01":"Aborted",
          "Day02":"Success",
          "Day03":"Success",
          "Day04":"Success",
          "Day05":"Success",
          "Day06":"Success",
          "Day07":"Success"
       },
    

    追加数据(dataBind.js)

    $.post("/portal/controllers/apis/test.jag", {
        action: "getData"
    }, function(data) {
    
        var result = JSON.parse(data);
        console.log("----------------------------------start----------------------------");
        var Day = result[result.length - 1].Days;
    
        $("#tableid").append("<thead><tr><th> Product </th> <th >" + Day[0].substring(5, 11) + "</th> <th>" + Day[1].substring(5, 11) + "</th> <th>" + Day[2].substring(5, 11) + "</th><th>" + Day[3].substring(5, 11) + "</th><th>" + Day[4].substring(5, 11) + "</th><th>" + Day[5].substring(5, 11) + "</th><th> Current </th><th> Failed Components </th><th> Failed Duration </th></tr></thead>");
    
        for (var i = 0; i < result.length; i++) {
            $("#tableid").append("<tbody><tr><td>" + result[i].product + "</td><td><img src='images/" + result[i].Day01 + ".png' /></td><td><img src='images/" + result[i].Day02 + ".png' /><td><img src='images/" + result[i].Day03 + ".png' /></td><td><img src='images/" + result[i].Day04 + ".png' /></td><td><img src='images/" + result[i].Day05 + ".png' /></td><td><img src='images/" + result[i].Day06 + ".png' /></td><td><img src='images/" + result[i].Day07 + ".png' /></td><td>" + result[i].Failed.Component + "</td><td>" + result[i].Failed.Duration + "</td></tr></tbody>");
    
        }
    
        console.log("----------------------------------End Table----------------------------");
    });
    

    HTML

        <html>
        <head>
    
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Build Data Table</title>
    
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <script language="javascript" type="text/javascript" src="js/jquery.js"></script>
        <script language="javascript" type="text/javascript" src="js/dataBind.js"></script>
    
        </head>
    
        <body style="height: 1100px;">
        <div class="CSSTableGenerator" >
        <table id = "tableid">
    
        </table>
        </div>
    
        </body>
        </html>
    

1 个答案:

答案 0 :(得分:1)

只需将from collections import defaultdict def getUnique(data): dd = defaultdict(lambda: 0) for value in data: dd[value] += 1 result = [key for key in dd.keys() if dd[key] == 1] result.sort() return result a = [5,4,3,2,2,1] b = getUnique(a) print(b) # [1, 3, 4, 5] print(b[1]) # 3 应用于自定义比较功能:

Array.prototype.sort