javascript - 向空的 tbody 元素添加行
问题描述
我有这样的表:
<table id="search-table" class="table">
<thead>
<tr>
<th>Something</th>
<th>Something2</th>
<th>Something3</th>
<th>Something4</th>
<th>Something5</th>
</tr>
</thead>
<tbody></tbody>
</table>
我有一个 API 调用,它返回我想作为行和列放在空 tbody 元素中的数据。
var body = document.getElementsbyTagName("tbody");
var x = 0;
for (i = 0; i < APIcall.length; i++) {
var createRow = body.insertRow();
for (j = 0; j < 7; j++) {
var x = createRow.insertCell(j);
}
}
如果我在 thead 元素上插入行,则会创建行,但当我尝试将其添加到 tbody 时不会。可能我只是误会了什么。有什么建议我应该怎么做?
解决方案
var html ='';
for (i = 0; i < APIcall.length; i++) {`enter code hereenter code here
html += '<tr><td>' + APIcall[i].somthing + '</td><td>'+ APIcall[i].somthing + '</td>' +
'<td>' + APIcall[i].somthing + '</td>' + < td > '+APIcall[i].somthing+' </td>'+
'<td>' + APIcall[i].somthing + '</td></tr>';
}
$('#search-table > tbody').append(html);
enter code here
推荐阅读
- r - 如何在survminer(ggforest)中向森林图添加箭头
- c++ - 服务器可以接受来自另一个子网的连接吗?
- javascript - 如何将深层表单数据作为数组或对象发送?
- python - 使用 Databricks 将 Google Api 的结果写入数据湖
- c# - 我的 css 文件不适用于 xmlworkloader
- c# - 如何使用 C# 使表格中的文本在 PowerPoint 上具有轮廓?
- pytorch - 使用 2d 张量索引 3d 张量
- java - 我在哪里可以下载 Java Mission Control(7)(OpenJDK11 或更高版本)?
- javascript - 从正文中获取所有文本并根据标签拆分
- visual-studio - Visual Studio 2019 下 tcm.exe 测试用例 /import 的替代方案