<!DOCTYPE html>
<html>
<head>
<title></title>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body onLoad="buildHtmlTable()">
<div id="excelDataTable">
</div>
<script type="text/javascript">
var myList = [
[{
"product": "Red Wine",
"unit": " ",
"max": "0.575",
"ruleNo": "1",
"ingredients": "sulphates",
"id": "2"
}, {
"product": "Red Wine",
"unit": " ",
"max": "10.25",
"ruleNo": "1",
"ingredients": "alcohol",
"id": "1"
}, {
"product": "Red Wine",
"unit": " ",
"max": "98.5",
"ruleNo": "1",
"ingredients": "total sulfur dioxide",
"id": "3"
}],
[{
"product": "Red Wine",
"unit": " ",
"max": "1.98",
"ruleNo": "3",
"ingredients": "sulphates",
"id": "8"
}, {
"product": "Red Wine",
"unit": " ",
"max": "81.5",
"ruleNo": "3",
"ingredients": "total sulfur dioxide",
"id": "9"
}, {
"product": "Red Wine",
"unit": " ",
"max": "10.25",
"ruleNo": "3",
"ingredients": "alcohol",
"id": "7"
}],
[{
"product": "Red Wine",
"unit": " ",
"max": "98.5",
"ruleNo": "2",
"ingredients": "total sulfur dioxide",
"id": "6"
}, {
"product": "Red Wine",
"unit": " ",
"max": "0.575",
"ingredients": "sulphates",
"id": "5"
}, {
"product": "Red Wine",
"unit": " ",
"max": "10.25",
"ruleNo": "2",
"ingredients": "alcohol",
"id": "4"
}],
[{
"product": "Red Wine",
"unit": " ",
"max": "1.98",
"ruleNo": "4",
"ingredients": "sulphates",
"id": "11"
}, {
"product": "Red Wine",
"unit": " ",
"max": "155",
"ruleNo": "4",
"ingredients": "total sulfur dioxide",
"id": "12"
}, {
"product": "Red Wine",
"unit": " ",
"max": "10.25",
"min": "8.5",
"target_state": "5",
"min_operator": "<=",
"max_operator": " ",
"target_parameter": "Quality",
"ruleNo": "4",
"ingredients": "alcohol",
"id": "10"
}]
];
// Builds the HTML Table out of myList json data from Ivy restful service.
function buildHtmlTable() {
for (var i = 0; i < myList.length; i++) {
var columns = addAllColumnHeaders(myList[0], i);
for (var j = 0; j < myList[i].length; j++) {
var row$ = $('<tr/>');
console.log(myList[i][j])
for (var colIndex = 0; colIndex < columns.length; colIndex++) {
var cellValue = myList[i][j][columns[colIndex]];
if (cellValue == null) {
cellValue = "";
}
row$.append($('<td/>').html(cellValue));
}
$("#table-id-"+i).append(row$);
}
}
// Adds a header row to the table and returns the set of columns.
// Need to do union of keys from all records as some records may not contain
// all records
function addAllColumnHeaders(list, i) {
var columnSet = [];
var headerTr$ = '<table id="table-id-'+i+'"><thead><tr>';
for (var i = 0; i < list.length; i++) {
var rowHash = list[i];
for (var key in rowHash) {
if ($.inArray(key, columnSet) == -1) {
columnSet.push(key);
headerTr$ += '<th>' + key + '</th>';
}
}
}
headerTr$ += '</tr></thead></table>';
console.log(headerTr$);
$("#excelDataTable").append(headerTr$);
return columnSet;
}
}
</script>
</body>
</html>
나에게 잘 보입니다. 이슈가 뭐야 ? –
은 들여 쓰기가됩니까? – Durga
내 실제 출력 모든 내용은 단일 테이블에 있지만 여기에 4 개의 다른 테이블에있는 데이터가 필요합니다 – user3872094