【发布时间】:2020-11-28 16:42:10
【问题描述】:
我有一个功能组件,它返回一个包含许多行的表,如下所示:
import React from "react";
import Checkbox from "@material-ui/core/Checkbox";
function Table({ data }) {
const [checked, setChecked] = useState(false);
const handleChange = (event) => {
setChecked(event.target.checked);
};
return (
// Some table head code
<TableBody>
{data.map((row) => (
<TableRow key={row.id}>
<TableCell align="left">
<Checkbox
checked={checked}
onChange={handleChange}
inputProps={{ "aria-label": "primary checkbox" }}
/>
</TableCell>
</TableRow>
// More table row code here
))}
</TableBody>
);
}
每一行都有一个复选框。问题是当我点击一个复选框时,其他行上的所有其他复选框都被选中。我该怎么办。
【问题讨论】:
-
您的意思是要添加“全选”功能吗?
-
不,我只想选中我选中的复选框,而不是全部。
标签: javascript reactjs material-ui