[英]How to populate data from backend in dropdownlist and select the value in Angular?
[英]Populate index value in column from the data in typescript(Angular/React)
我有以下数组。 我试图在下面的表格中填充格式。第一个字段是排名然后玩家名称应该从零开始一个一个地排列。
0:Array(3)
0:{fullname:'john'}
1:{fullname:'kennedy'}
2:{fullname:'sachin'}
1:Array(3)
0:{fullname:'dravid'}
1:{fullname:'dhoni'}
2:{fullname:'kohli'}
2:Array(3)
0:{fullname:'mcrath'}
1:{fullname:'murali'}
2:{fullname:'dinesh'}
我的代码在下面。它不起作用。 排名列未正确显示 排名列应从 1 自动递增。
{this.props.data.map((row, index) => {
return (
<tr>
{row.map((col, colIndex) => {
return (
<td> {col.index} </td>
<td> {col.fullname} </td>
)
})}
</tr>
)
})}
您应该使用外部地图的index
并且由于索引以0
开头,因此您应该根据需要添加 1:
<td> {index+1} </td>
尝试这个
this.props.data.map((row, index) => (
<tr key={index}>
<td> {index + 1} </td>
{row.map((col, colIndex) => (
<td key={colIndex}> {col.fullname} </td>
))}
</tr>
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.