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;
react 遍历生产form表单(FormItem)
最新推荐文章于 2024-06-03 14:37:05 发布