pass id through on click react.js

前端 未结 6 1566
暖寄归人
暖寄归人 2020-12-08 16:52

Below is my partial code but my question is very simple, how can I get says data-id=\"1\" to my function when user clicked on the li?

render(){
         


        
6条回答
  •  半阙折子戏
    2020-12-08 17:23

    Since you are already using ES6 - might be a little cleaner to use an arrow function here:

    render(){
        return(
          
      {this.state.items.map((item,i) =>
    • {item.name}
    • )}
    ) }

提交回复
热议问题