使用带有reactjs的香草表将单行拆分为多行
我无法从JSON获取的数据中分割表行 代码如下所示:使用带有reactjs的香草表将单行拆分为多行,reactjs,html-table,Reactjs,Html Table,我无法从JSON获取的数据中分割表行 代码如下所示: <table> <thead> <tr> <th scope="col">Location ID #</th>
<table>
<thead>
<tr>
<th scope="col">Location ID #</th>
<th scope="col">Device Name</th>
</tr>
</thead>
<tbody>
{Object.keys(deviceList).map((key, index) => {
return (
<tr key={index}>
{deviceList[key].ports.map(port => port.value.id)
.map(ids => {
console.log("type", typeof(ids)) // it says number
return <td>{ids}</td>
})
}
</tr>
)
})}
</tbody>
</table>
上面的结果是因为一个端口可以有多个ID,但它会在下一行中并行显示。所以有三个端口,portA有两个设备,portB有两个设备,portC只有一个
expected result:
ID. Name.
23301
24401
99501
87701
22201
我可以通过改变我实现它的方式来修复它
{Object.keys(deviceList).map(key => {
return deviceList[key].ports.map(port => {
return (
<tr>
<td> {port.value.siteId}</td>
<td>{port.value.name}</td>
<td>{deviceList[key].value.targetId === undefined ? deviceList[key].value.name : deviceList[key].value.targetId}</td>
<td>{deviceList[key].value._type}</td>
<td>{port.description === undefined ? deviceLookup[key].value.name : deviceList[key].value.name + ' ' + "[" + port.description + "]"}</td>
</tr>
)
})
})
}
{Object.keys(deviceList).map(key=>{
返回设备列表[key].ports.map(端口=>{
返回(
{port.value.siteId}
{port.value.name}
{deviceList[key].value.targetId==未定义?deviceList[key].value.name:deviceList[key].value.targetId}
{deviceList[key].value.\u type}
{port.description===未定义?deviceLookup[key]。value.name:deviceList[key]。value.name+''+'[“+port.description+']]”
)
})
})
}
我可以通过改变实现它的方式来修复它。{Object.keys(deviceLookup).map(key=>{return deviceLookup[key].ports.map(port=>{return({port.parentSite[0].value.siteId}{port.parentSite[0].value.name}
{Object.keys(deviceList).map(key => {
return deviceList[key].ports.map(port => {
return (
<tr>
<td> {port.value.siteId}</td>
<td>{port.value.name}</td>
<td>{deviceList[key].value.targetId === undefined ? deviceList[key].value.name : deviceList[key].value.targetId}</td>
<td>{deviceList[key].value._type}</td>
<td>{port.description === undefined ? deviceLookup[key].value.name : deviceList[key].value.name + ' ' + "[" + port.description + "]"}</td>
</tr>
)
})
})
}