简体   繁体   English

从打字稿(Angular/React)中的数据填充列中的索引值

[英]Populate index value in column from the data in typescript(Angular/React)

I have the below array.我有以下数组。 I tried to populate in table below format.First field is ranking then player name should one by one from zero the array.我试图在下面的表格中填充格式。第一个字段是排名然后玩家名称应该从零开始一个一个地排列。

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'}

在此处输入图片说明

My code is below.it is not working.我的代码在下面。它不起作用。 Ranking column not showing correctly Ranking column should auto increment from 1 .排名列未正确显示 排名列应从 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> 

Try this尝试这个

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM