【发布时间】:2018-06-17 12:44:25
【问题描述】:
我有一些 JSON 想要放入表格中,但 dict 中的一项应该在顶部的单独表格中。
{
"test": {
"col1": 1, "col2": 2, "col3": 3, "col4": 4, "col5": 5
},
"test2": {
"col1": 1, "col2": 2, "col3": 3, "col4": 4, "col5": 5
}
}
我想循环遍历测试字典并从它们下面解析表格,如下所示:
我让它适用于 1/2/3/4/5 表,但我也无法将上面一行放入代码中......与:
$(function() {
var tbody = $("<tbody />"),
tr;
$.each(trades, function(_, obj) {
tr = $("<tr />");
$.each(obj, function(_, text) {
tr.append("<td>" + text + "</td>")
});
tr.appendTo(tbody);
});
tbody.appendTo("#trades_table");
})
<table class="table" id="trades_table">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
</table>
【问题讨论】:
标签: javascript html json html-table