赞
踩
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;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。