首页 > 解决方案 > antd 中的 getFieldDecorator 是什么,React 中的 getFieldDecorator 有什么用?

问题描述

  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>
);

我想为此添加一个默认值。你能帮忙吗

标签: reactjsantd

解决方案


使用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>

推荐阅读