$(function () { var table = $("#infoTable")[0]; pageObj.SacInfoList.forEach(Obj => { formatHtml(Obj, table, 1); }) }) function formatHtml(obj, table, rowIndex) { if (obj.FieldName !== "Root" && obj.FieldName !== "Header" && obj.FieldName !== "Body") { var html = '{1}{2}{3}'.template(obj.FieldName, obj.FieldDescribe, obj.FieldValue, obj.ShowMessage); rowIndex = addRow(table, rowIndex, html); } if (obj.SubInfos && obj.SubInfos.length > 0) { obj.SubInfos.forEach(function (item) { rowIndex = formatHtml(item, table, rowIndex); }); } return rowIndex; } function addRow(table, rowIndex, htmlStr) { var row = table.insertRow(rowIndex); row.innerHTML = htmlStr; rowIndex += 1; return rowIndex; }