search

Home  >  Q&A  >  body text

javascript - React develops table components by itself. How to get the ID of the current row when clicking within a row?

class ManageTable extends Component{
showModal(){

}
render(){
    return(
        <tr id={user.id}>
        <td>{}</td>
        <td>{}</td>
        <td>{}</td>
        <td>{}</td>
        <td ref="viewDatail"><a onClick={this.showModal}>查看详情</a></td>
        </tr>
        )
    }
}

export default ManageTable;

Click to view details, how to get the ID of the current row.

I want to complete the next step. The first step is to obtain the ID. How to achieve this?
Seek the guidance of the great God.

淡淡烟草味淡淡烟草味2756 days ago810

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-19 10:27:02

    showModal(event) {
        event = event.nativeEvent;
        const tr = event.target.parentNode;
        console.log(tr.id);
    }

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:27:02

    Try it:
    <td ref="viewDatail"><a onClick={this.showModal.bind(this)}>查看详情</a></td>

    reply
    0
  • Cancelreply