在antd中,getFieldDecorator是什么?在React中,getFieldDecorator的用途是什么?

时间:2019-04-23 06:41:50

标签: reactjs antd

  initialValue: formData.orderInfo ? formData.orderInfo.netWtUnits : 'MT',
  onChange: e => this.handleUnitsChange(e, 'orderInfo.netWtUnits'),
  rules: [
    {
      required: this.props.contract=="No"?true:false,
      message: 'Please input Weight Units!'
    }
  ]
})(
  <Select placeholder="MT" style={{ width: 55 }}>
    <Select.Option value="MT">MT</Select.Option>
    <Select.Option value="KG">KG</Select.Option>
  </Select>
);

我要为此添加默认值。请您帮忙

1 个答案:

答案 0 :(得分:0)

使用defaultValue属性

<Select defaultValue="MT"/>

重量选项示例:

const weightOptions = ["MT", "KG"];

const addWeightOptions = weightOptions =>
  weightOptions.map((weight, i) => (
    <Select.Option key={`${weight}-${i}`} value={weight}>
      {weight}
    </Select.Option>
  ));

<Select
    placeholder="Select Weight Units"
    defaultValue={weightOptions[0]}
  >
    {addWeightOptions(weightOptions)}
</Select>