reactjs - 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>
);
我想为此添加一个默认值。你能帮忙吗
解决方案
使用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>
推荐阅读
- css - 尽管定义了表格并应用固定表格布局,但表格的每一列都有不同的宽度
- angular - angular 6 pwa 无法正常工作
- java - 如何在 Android 中以编程方式将图标设置为警报对话框
- swift - Swift 4 - 创建具有 2 种背景颜色的 UIView
- python - ASCII Characters Text Align
- swift - 按下按钮时,如何将表格视图中单元格的索引从一个视图控制器传递到下一个视图控制器?
- java - 最新版 Android Studio 中文本视图的文本对齐选项在哪里?
- apache - 安装后apache上的语法错误让加密
- frameworks - 机器人框架-如何用包含文件列表的 .csv 文件替换“目录中的列表文件”关键字
- html - HTML 列表样式