[React] Antd Form.List 的基本使用
Form.List 为字段提供数组化管理。
官网:https://ant.design/components/form-cn/#Form.List
<Form.List name='infoList'>
{(fields, {add, remove}) => (
<>
<FormItem>
{gettext('用户填写信息')}
<Button
type='primary'
style={{marginLeft: '20px'}}
ghost
disabled={!canEdit}
shape='circle'
onClick={() => add()}
>
+
</Button>
</FormItem>
<FormItem>
<div style={{color: '#999'}}>{gettext('请在下方输入框中配置用户需要填写的信息标题,如手机号码')}</div>
</FormItem>
{fields.map(({key, name, ...restField}) => (
<div className='infoItem' key={key}>
<div className='removeBtn'>
<Button danger ghost shape='circle' disabled={!canEdit} onClick={() => remove(name)}>
-
</Button>
</div>
<FormItem label={gettext('中文标题')} name={[name, 'info']} required rules={utils.form.setRules()}>
<Input disabled={!canEdit} placeholder={gettext('请输入中文标题')} />
</FormItem>
<FormItem label={gettext('英文标题')} name={[name, 'infoEn']} required rules={utils.form.setRules()}>
<Input disabled={!canEdit} placeholder={gettext('请输入英文标题')} />
</FormItem>
</div>
))}
</>
)}
</Form.List>
页面样式:
数据结构:
infolist: [
{info:'姓名',infoEn:'Name'},
{info:'邮箱',infoEn:'Email'},
]