在 Ant Design 中,如果要清除所有复选框的选中状态,可以使用 Form 组件的 resetFields 方法。以下是一个示例代码:
import { Form, Checkbox, Button } from 'antd';
const CheckboxGroup = Checkbox.Group;
const options = [
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
{ label: 'Orange', value: 'orange' },
];
const App = () => {
const [form] = Form.useForm();
const handleReset = () => {
form.resetFields(); // 清除所有复选框的选中状态
};
return (
);
};
export default App;
在上面的示例中,通过 form.resetFields()
方法可以清除所有复选框的选中状态。在点击 Reset 按钮时,会触发 handleReset
方法,然后调用 form.resetFields()
来清除复选框的选中状态。