我使用 Material UI 制作了一个表格,其中每一行的第一列都有两个按钮。我希望通过单击这些行来编辑/删除行,但我坚持逻辑。我的实施甚至有可能吗?如果不是,那么这样做的首选方式是什么?
render() {
var deleteIcon =
(<IconButton onClick={console.log("delete")}>
<DeleteIcon color="secondary" />
</IconButton>
);
const editIcon = (
<IconButton onClick={console.log("edited")}>
<EditIcon color="primary" />
</IconButton>
);
return(
<TableBody>
{this.state.serviceData.map(n => {
return (
<TableRow key={n.id}>
<TableCell style={styles.editor} component="th" scope="row">
{deleteIcon}
{editIcon}
</TableCell>
<TableCell>{n.domain}</TableCell>
<TableCell>{n.service_name}</TableCell>
</TableCell>
</TableRow>
)};
原文由 Yashank 发布,翻译遵循 CC BY-SA 4.0 许可协议
基于@st4rl00rd 的评论,我能够使用以下方法绑定按钮:
并将它们绑定到构造函数中。我能够通过执行以下操作获取选定的行数据: