当前位置:   article > 正文

react 遍历生产form表单(FormItem)_react 循环form.item

react 循环form.item
import React, { PureComponent } from 'react';
import { Form, Input } from 'antd';
const FormItem = Form.Item;
@Form.create()
class Formany extends PureComponent {
  render() {
    const {
      form: { getFieldDecorator },
      modalData,
      modalDataStruct,
    } = this.props;
    console.log("这是传值到表单的数据", modalData)
    console.log("这是传值到表单的数据结构", modalDataStruct[0])
    function getItems(d){
      return Object.keys(d).map((key) =>
      (
        <FormItem key={key}>
          {
            getFieldDecorator(key, { rules: [{ required: true, message: key }] })(<Input placeholder={modalData[key] || key} />)
          }
        </FormItem>
      ));
    }

    const items = modalData && typeof modalData === 'object'? getItems(modalData) : getItems(modalDataStruct[0]);
    
    return (
      <div>
        <Form name="normal_login" className="login-form" onSubmit={this.handleSubmit}>
          {items}
        </Form>
      </div>
    );
  }
}

export default Formany;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/115582
推荐阅读
相关标签
  

闽ICP备14008679号