[英]Can't apply an onClick function to <TableRowColumn> in React with Material-UI
I formerly had functionality whereby I could click on the cell of a table
and it would toggle the colour of the text between red and green. 我以前有功能,可以单击
table
的单元格,它将在红色和绿色之间切换文本的颜色。
I have since implemented Material-UI in the React app, replacing the <td>
tags with <TableRowColumn>
tags, to which now I find that the onClick event no longer works. 此后,我在React应用程序中实现了Material-UI,用
<TableRowColumn>
标签替换了<td>
标签,现在我发现onClick事件不再起作用。
I have tested the functionality of onClick by placing a <button>
within the <TableRowColumn>
, which DOES infact work. 我已经通过将测试的onClick的功能
<button>
内的<TableRowColumn>
这DOES INFACT工作。 So this leads me to believe that the <TableRowColumn>
element does not have the option for onClick... 因此,这使我相信
<TableRowColumn>
元素没有onClick选项。
Working 工作中
return (
<tdstyle={taskStyle} onClick={this.props.toggleTask.bind(this, task)}>
{task} <button >Click</button>
</td>
)
Broken (The colour change functionality works when called from the button) 损坏(从按钮调用时,变色功能有效)
return (
<TableRowColumn style={taskStyle} onClick={() => this.help()}>
{task} <button onClick={this.props.toggleTask.bind(this, task)} >Click</button>
</TableRowColumn>
)
Function 功能
toggleTask(task) {
const foundToDo = _.find(this.state.todos, todo => todo.task === task);
foundToDo.isCompleted = !foundToDo.isCompleted;
this.setState({ todos: this.state.todos });
}
I believe you have to add an onCellClick
function to the Table component that takes the row and column indices as parameters. 我相信您必须向表组件添加
onCellClick
函数,该函数将行索引和列索引作为参数。
handleCellClick(row, column, e) {
if(row == 0)
...
if(column == 0)
...
}
You may have to implement a way to lookup the task based its column & row. 您可能必须实现一种基于任务的列和行来查找任务的方法。 This would handle changing the color of the cell's text
这将处理更改单元格文本的颜色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.