Yas*_*ank 2 javascript reactjs material-ui
我使用 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>
)};
Run Code Online (Sandbox Code Playgroud)
根据 @st4rl00rd 的评论,我能够使用以下方法绑定按钮:
const editIcon = (
<IconButton onClick={this.editItem}>
<EditIcon color="primary" />
</IconButton>
);
Run Code Online (Sandbox Code Playgroud)
并将它们绑定在构造函数中。我能够通过执行以下操作来获取所选行数据:
<TableBody>
{this.state.serviceData.map(n => {
return (
<TableRow key={n.id} onClick={this.getData.bind(this,n)}>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32820 次 |
| 最近记录: |