![](/img/trans.png)
[英]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.