我正在使用 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 时,会调用警报。要使您的代码正常工作,请使用 bind
方法:
alert.bind(null,columnIndex); // alert will always have columnIndex's value as the first argument
关于javascript - 在react-virtualized网格单元/行中使用onClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39228220/