Asp.net 我的模态如何知道行中的索引

Asp.net 我的模态如何知道行中的索引,asp.net,reactjs,Asp.net,Reactjs,我是这门语言的初学者,我以前使用过php。 因此,表有一个按钮,当我点击按钮时,它只读取第一行,不会读取其他行,在php中,我使用了函数attr,因此它将读取其他单击的行,在reactjs,我不知道如何帮助 return <tr key={i} > <td>{d.Employee_Name}</td> <td>{d.Address}</td> <td><center&g

我是这门语言的初学者,我以前使用过php。 因此,表有一个按钮,当我点击按钮时,它只读取第一行,不会读取其他行,在php中,我使用了函数attr,因此它将读取其他单击的行,在reactjs,我不知道如何帮助

return <tr key={i} >
        <td>{d.Employee_Name}</td>
        <td>{d.Address}</td> 
        <td><center><button className ="btn btn-info" onClick={ this.props.onClick }   data-toggle="modal" data-target="#UpdateEmployee">Update</button></center></td>
  <td><center><button className ="btn btn-danger">Delete</button></center></td>

<div className="modal fade" id="UpdateEmployee" role="dialog">
         <div className="modal-dialog">
           <div className="modal-content">
              <div className="modal-header">
                <button type="button" className="close" data-dismiss="modal">&times;</button>
                <h4 className="modal-title">Update Employee</h4>
              </div>
          <div className="container">
            <div className="modal-body">
                <table> 
                <tbody>
                <tr>
                <td>Name</td>
                <td> <input type="text"value={ d.Employee_Name} /> </td>
                </tr>
                <tr>
                <td>Address</td>
                <td><input type="text" value={ d.Address} />  </td>
                </tr>
                </tbody>
                </table>

            </div>
            </div>
            <div className="modal-footer">
              <botton className="btn btn-info"> Update Employee</botton>
              <button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
            </div>
          </div>
        </div>
      </div>
        </tr>
}
返回
{d.Employee_Name}
{d.Address}
更新
删除
&时代;
更新员工
名称
地址
更新员工
接近
}

要获取所单击项目的索引,您需要将每个元素的索引绑定到
onClick
函数,如下所示:

<td>
    <center>
         <button ... onClick={() => this.props.onClick(i) }></button>
    </center> 
</td>
onClick(index){
   console.log(index); // it will print the index of item clicked
}

你能展示一下你是如何使用map创建ui的吗?@MayankShukla{jsonReturnedValue.map((d,i)=>this.renderItem(d,i))}只需将对象的id传递给onClick函数,就像这个Updatestill一样。。它只读取表格的第一行,在模态的输入中…你没有在onClick函数中获得不同的索引?对不起,我只是不知道你的意思,但我把你告诉我的话放在绑定了onClick函数的值i后(正如我在代码片段中提到的),当你点击按钮时,你没有在那个函数中得到i的值吗?它没有任何作用,他们告诉我应该从api调用id以便模态读取它,但我不知道如何读取