React中Form表单数据获取

const { getFieldDecorator } = this.props.form;

this.getFieldsValue = this.props.form.getFieldsValue;//获得表单所有控件的值

this.props.form.getFieldsValue(“name”)//获得指定控件的值

在ant design 2x 中

{getFieldDecorator('note', { rules: [{ required: true, message: 'Please input your note!' }], })( <Input />)

getFieldDecorator 用于和表单进行双向绑定,其中

经过 getFieldDecorator 包装的控件,表单控件会自动添加 value,数据同步将被 Form 接管

 {
        title: '付款金额',
        dataIndex: 'needPayPrice',
        key: 'needPayPrice',
        width: 120,
        render: (text, record, index) => {
          return (<FormItem style={{ marginBottom: 0 }}>{this.getFieldDecorator(`needPayPrice_${index}`, {
            initialValue: record.no_pay_amount,
            rules: [
              {
                message: '请填写正确的付款金额',
                pattern: /(^[0-9]{1,9}$)|(^[0-9]{1,9}[.]{1}[0-9]{1,2}$)/,
                required: true,
              },
              {
                validator: (rule, value, callback) => {
                  if (Number(value) <= 0) {
                    callback('请填写正确的付款金额');
                  }
                  callback();
                },
              },
            ],
            validateFirst: true,
          })(<Input placeholder="付款金额" style={{ width: 80 }} />)}
          </FormItem>);
        },
      },

猜你喜欢

转载自blog.csdn.net/linlinlinfeng/article/details/82781812