当后台返回json格式,如下:
[ { "顾问":"小明", "一节点":3, "二节点":4, "三节点":0, "四节点":9 }, { "顾问":"小刚", "一节点":34, "二节点":234, "三节点":7, "四节点":1 }, ...... ]
js:
function logsDataHandle(arr) { for (var i = 0; i < arr.length; i++) { var arrTitle = Object.keys(arr[0]);//获取数据当表头 } // 渲染页面 renderTable(arrTitle, arr); } function renderTable(arrTitle, arr){ var html = ''; var tableB = ''; for (var k = 0; k < arr.length; k++) { tableB += '<tr>'; for (var i in data) { var name = data[i]; if (name != 'adminuser') {//表头为adminuser时,不显示 if (k == 0) { html += '<th>' + name + '</th>'; } tableB += '<td class="">' + arr[k][name] + '</td>'; } tableB += '</tr>'; } var tableH = '<tr class="thead">' + html + '</tr>'; $(".render-table-head").html(tableH); $(".render-table-body").html(tableB); }