Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

antd中控制部分表单显示或隐藏

需求是根据一个选项选中值来判断是否显示下面内容
比如

选中1后显示 一部分表单
选中2后显示 一部分表单
二者只能显示一个

我现在是用变量控制表单的显示或隐藏

image.png

结构就是

<Form>
{this.state.form1Show && (
<div>
<Form.Item lable='name'>
{getFieldDecorator('name', {
  initialValue: '',
   })(
      <Input  />
   )}
</Form.Item>
<Form.Item lable='城市'>
{getFieldDecorator('city', {
  initialValue: '',
   })(
      <Input  />
   )}
</Form.Item>
</div>
)}
</Form>

form.item表单外层套了一个div
然后表单创建完成后 查看创建完成的表单时
this.props.form.setFieldsValue(具体值)
数据无法填充进去

有大神解决过类似的问题吗


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

根据状态值显示不同组件是没问题的。
数据无法填充是因为
initialValue没有赋初始值
参考文档https://ant.design/components/form/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...