data is like this, and you need to use this to generate a form like this
{
name: "", //
groups: [ //
{
groupName: "", //
state: 1, // 1 0
isOpen: 1, // 1 0
fields: [ //
{
fieldNameCn: "", //
tableName: "", //
fieldName: "", //
state: 1 // 1 0
}
]
}
]
}
Click the add Group button to add a piece of data to groups
, click the new field to add a piece of data to groups [x] .fields
, and vice versa
now loop out the initial form, no problem, use a method similar to the following to register a field for antd
{getFieldDecorator(`groups[${index}].groupName`, {})()}
now, when you click add, use the following method to set field to report You cannot set field before registering it.
, because I did not register groups [1] .groupName
, because it is new, it is impossible for me to register it when render traverses.
appGroup = () = > {
const { form } = this.props;
const groups = form.getFieldValue("groups");
const group_empty = this.data_form_empty.groups[0]; //
const key = `groups[${groups.length}]`
form.setFieldsValue({ // You cannot set field before registering it.
[key]: group_empty
});
}
has also tried to register a groups
directly with getFieldDecorator
, and then directly setFieldsValue
the entire groups. However, due to the complexity of the structure, people will register things like groups [${index}] .groupName
when getFieldDecorator
, so they will report Warning: One field name cannot be part of another, rooma and a.b.