我目前正在尝试在React中使用HTML表格,但是有些地方似乎不太对。我确实可以得到一个渲染输出,但是会出现以下错误:
我尝试在网上找到解决方法,但是我使用的技术似乎并不常用,所以如果我做错了,请指教。
提前感谢!
数据如下所示:
<tr> cannot appear as a child of <div>
。我尝试在网上找到解决方法,但是我使用的技术似乎并不常用,所以如果我做错了,请指教。
提前感谢!
getTableContent = (arr) => {
let result = [];
arr.forEach(function (item, i) {
result.push(
<table key={item.productType}>
<thead>{item.productType}</thead>
<tbody>
{item.contents.forEach(function (nextItem, j) {
result.push(
<tr key={nextItem.type}>
<td>{nextItem.type}</td>
<td>{nextItem.count}</td>
</tr>
)
})}
</tbody>
</table>
);
});
return result;
};
render() {
return (
<div>{this.getTableContent(productSpecification)}</div>
);
}
数据如下所示:
const productSpecification = [
{
productType: "abc", contents: [
{type: "abc", count: 231},
{type: "abc", count: 56},
{type: "abc", count: 54},
{type: "abc", count: 544},
{type: "abc", count: 54},
{type: "abc", count: 564},
{type: "abc", count: 4},
{type: "abc", count: 4564},
{type: "abc", count: 4531},
{type: "abc", count: 234},
{type: "abc", count: 57},
{type: "abc", count: 7}
]
}
];