Created
February 15, 2017 15:01
-
-
Save hansnow/5f69e30cd6f4e4b9ca2b373118249562 to your computer and use it in GitHub Desktop.
ant design 表单例子,120个field放在一个Form里面的时候会卡顿
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Form, Card, Input, Row, Col } = antd | |
class MyForm extends React.Component { | |
render() { | |
const names = ['A', 'B', 'C', 'D', 'E', 'F'] | |
const inputCount = 20 | |
const formItemLayout = { | |
labelCol: { span: 4 }, | |
wrapperCol: { span: 20 } | |
} | |
const subForms = names.map(name => { | |
const fields = Array.from(Array(inputCount).keys()).map(key => { | |
const {getFieldDecorator} = this.props.form | |
return ( | |
<Row key={key}> | |
<Form.Item label={`${name}-${key}`} {...formItemLayout}> | |
{getFieldDecorator(`${name}-${key}`)(<Input/>)} | |
</Form.Item> | |
</Row> | |
) | |
}) | |
return ( | |
<Col span={4} key={name}> | |
<Card title={`Form${name}`}> | |
{fields} | |
</Card> | |
</Col> | |
) | |
}) | |
return ( | |
<Form> | |
<Row gutter={8}> | |
{subForms} | |
</Row> | |
</Form> | |
) | |
} | |
} | |
const WrappedMyForm = Form.create()(MyForm) | |
ReactDOM.render(<WrappedMyForm />, document.getElementById('container')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment