表格行中的onClick函数

时间:2019-01-07 10:05:19

标签: javascript reactjs

我有一张桌子,当我单击每一行时,应该从响应中获取该行的坐标,如何获取点击函数上的response.geometry

  gotoCoord = (e) => {
            //click function where ı click row and need to get the response.geometry 
          }
          renderParselResult = () => {
            return this.state.parselResult.map(response => {
              console.info(`res geo`, response.geometry)
              return (
                <tr key={response.attributes.OBJECTID} onClick{this.gotoCoord}>
                  <td>{response.attributes.ILCE_ADI}</td>
                  <td>{response.attributes.ADA}</td>
                  <td>{response.attributes.PAFTA}</td>
                  <td>{response.attributes.PARSEL}</td>
                  <td></td>
                </tr>
              )
            })
          }

1 个答案:

答案 0 :(得分:0)

首先,我不得不说将事件处理程序添加到非交互式元素是一种不好的做法。但是要回答您的问题,只需将其作为参数传递给函数。

goToCoord = (geometry) => {
  // do something
}

renderParselResult = () => {
  return this.state.parselResult.map(response => {
    console.info(`res geo`, response.geometry)
    return (
      <tr
        key={response.attributes.OBJECTID}
        onClick{() => this.gotoCoord(response.geometry)} // <-- 
      >
        <td>{response.attributes.ILCE_ADI}</td>
        <td>{response.attributes.ADA}</td>
        <td>{response.attributes.PAFTA}</td>
        <td>{response.attributes.PARSEL}</td>
        <td></td>
      </tr>
    )
  })
}