antd form表單數組對象格式


我們在做表單的時候經常會遇到一個場景需要數組對象格式的數據,例如我們填寫公司成員信息,如下圖:

 

 我們需要的數據格式是數組對象,這時我們在getFieldDecorator要如何取名字呢?

         <Form.Item style={{ margin: 0 }}>
            {getFieldDecorator(`content[${index}].name`, {
              rules: [
                {
                  required:true,
                  message: '請輸入姓名!',
                },
              ],
              initialValue:...,
            })(<Input />)}
          </Form.Item>
           <Form.Item style={{ margin: 0 }}>
            {getFieldDecorator(`content[${index}].workId`, {
              rules: [
                {
                  required:true,
                  message: '請輸入工號!',
                },
              ],
              initialValue:...,
            })(<Input />)}
          </Form.Item>          

此時我們如果想獲取這個數組對象內容可以通過:

let param = getFieldsValue(['content'])獲取


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM