我的 react 项目中有一个引导表。我想获取我点击的行的索引。我想做这样的事情 onclick = {this.handleClick} 并在handleClick 函数中我想获取行的索引。是否可以做到呢。大多数可用的解决方案都显示了使用 jquery 的所有内容,但我不想使用 Jquery。我想只使用 javascript 来完成它。这是我的 table
<Table className='flags-table' responsive hover>
<thead>
<tr>
<th> </th>
<th> Time In </th>
<th> Time Out </th>
<th> Type </th>
<th> Category </th>
</tr>
</thead>
<tbody>
{
FLAGS_LIST.map((x,i)=> (
<tr key={i}>
<td> <div className='red-box'></div> </td>
<td> {x.time_in} </td>
<td> {x.time_out} </td>
<td> {x.type} </td>
<td> {x.category} </td>
</tr>
))
}
</tbody>
</Table>
最佳答案
您可以使用这样的代码:
onclick = {this.handleClick.bind(this, i)};
和handleClick
应该这样声明:
var handleClick = function(i) {
console.log("key of row", i)
...
};
关于javascript - 不使用jquery在click中获取bootstrap表的行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41890376/