在 antd 4 中将初始值设置为动态形式

我在antd4中创建动态表单时遇到了一个问题,请按照文档中的此示例进行操作

我想使用动态表单来编辑已经具有一些值的对象。

在此沙盒中,我创建了一个新的初始值数组:https://codesandbox.io/s/dynamic-form-item-ant-design-demo-slm8o?file=/index.js:636-649

目标是在打开表单时实现此状态:

http://img4.mukewang.com/62eb98c30001728905470300.jpg

幕布斯7119047
浏览 179回答 1
1回答

慕尼黑8549860

您需要将一个对象传递给 prop,其中包含字段列表的值数组,如下所示:initialValuesnames&nbsp; &nbsp; <Form&nbsp; &nbsp; &nbsp; name="dynamic_form_item"&nbsp; &nbsp; &nbsp; initialValues={{ names: ['', '', ''] }}&nbsp; &nbsp; &nbsp; {...formItemLayoutWithOutLabel}&nbsp; &nbsp; &nbsp; onFinish={onFinish}&nbsp; &nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; <Form.List name="names">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { /* your array of fields goes here */ }&nbsp; &nbsp; &nbsp; &nbsp; </Form.List>&nbsp; &nbsp; </Form>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript