【问题标题】:what is getFieldDecorator in antd and what is the use of getFieldDecorator in React?antd 中的 getFieldDecorator 是什么,React 中的 getFieldDecorator 有什么用?
【发布时间】:2019-04-23 06:41:50
【问题描述】:
  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>
);

我想为此添加一个默认值。请您帮忙

【问题讨论】:

  • 你能把整个代码贴出来吗?
  • 根据ant design的documentation。 getFieldDecorators 是一个Two-way binding for form。 React 中没有 getFieldDecorators,这是一个 ant-design API。

标签: reactjs antd


【解决方案1】:

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

【讨论】:

  • 我可以知道 getFieldDecorator 可以做什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-06
  • 2020-01-19
  • 1970-01-01
  • 1970-01-01
  • 2020-02-07
  • 2020-02-22
  • 2019-08-02
相关资源
最近更新 更多