Ant Form使用總結(jié) —— FormList

NO.2 FormList 極簡用法

FormList是為了表單種具有多數(shù)據(jù)Array形式(類似批量),話不多說,直接盜圖!

image.png
import React from "react";
import { Form, Input, Row, Col, Button } from "antd";

//initalValue.files 有一元素 可直接顯示一行樣式 可以實驗性看下樣式
//可以看到 { add , remove } 暴漏的這兩個方法顯而易見可用來添加刪除項
//可各種組合 華山論劍

export default () => (
  <Form initialValues={{ files : [{ file : '' , name : '' }] }}>  
    <Form.Item label="文件">
      <Form.List name="files">
        {
            ( fields , { add, remove }) => fields.map(
              field => (
                <>
                  <Row key={ field.key }>
                    <Col span={ 11 }>
                      <Form.Item name={[ field.name , 'file']}>
                        <Input />
                      </Form.Item>
                    </Col>
                    <Col span={ 11 }>
                      <Form.Item  name={[ field.name , 'name']}>
                        <Input />
                      </Form.Item>
                    </Col>
                    <Col span={ 2 } onClick={ remove( field.name ) }>x</Col>
                  </Row>
                  <Row>
                    <Button onClick={ add( field.name ) }>添加一行</Button>
                  </Row>
                </>
              )
            )
        }
      </Form.List>
    </Form.Item>
  </Form>
);

如上代碼

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容