因为我使用useState设置值,输入框的内容设置不上,所以在想是不是需要使用表单的方法设置
Antd表单,name为一个数组,怎么通过setFieldsValue来设置输入框的值,
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
关注 你可以参考一下
import React, { useRef, useEffect } from "react"; import { Form, Input, Button, Select } from "antd"; import "./index.less"; const { Option } = Select; const layout = { labelCol: { span: 4 }, wrapperCol: { span: 20 } }; const tailLayout = { wrapperCol: { offset: 8, span: 16 } }; function AddFrom(props) { const formRef = useRef({ name: '', parentType: '0' }); const onFinish = values => { props.onOk(values); formRef.current.resetFields(); }; const onCancel = () => { props.onCancel(); formRef.current.resetFields(); }; useEffect(() => { formRef.current.setFieldsValue({ name: props.name, }); }) return ( <Form {...layout} ref={formRef} name='control-hooks' onFinish={onFinish} initialValues={{ name: '', parentType: '0' }} > <Form.Item name='parentType' label='所属分类' rules={[{ required: true }]} > <Select placeholder='请选择所属分类' allowClear > <Option value='0'>一级分类</Option> </Select> </Form.Item> <Form.Item name='name' label='分类名称' rules={[ { required: true, whitespace: true, message: "请输入分类名称!" }, { min: 2, message: "名称至少2位" }, { max: 12, message: "名称最多12位" } ]} > <Input placeholder='请请入分类名称' /> </Form.Item> <Form.Item {...tailLayout}> <Button type='primary' htmlType='submit'> 确定 </Button> <Button htmlType='button' onClick={onCancel} className='cancelBtn' > 取消 </Button> </Form.Item> </Form> ); } export default AddFrom;
解决 无用评论 打赏 举报
悬赏问题
- ¥15 outlook无法配置成功
- ¥15 Pwm双极模式H桥驱动控制电机
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换