在 react-virtualized Grid 中使用 onClick cell/row

Using onClick in react-virtulized Grid cell/row

我正在使用 react-virulized 中的 Grid 组件,需要在列单元格和行级别处理点击事件。 我尝试将 onClick 添加到我的 cellRenderer 方法返回的 div,但它似乎不起作用。有没有人得到这个工作?见下文:

_renderCell ({ columnIndex, rowIndex }) {
    // name = getFrom(columnIndex, rowIndex)
    return (
      <div className={'cell'} >
        <input type="text" {name} maxLength={2} onClick={alert(columnIndex)}/>
      </div>
    )
  }

谢谢!

目前你调用函数而不是引用它,所以当加载DOM时,警报得到called.To 使用 bind 方法让你的代码工作:

alert.bind(null,columnIndex); // alert will always have columnIndex's value as the first argument