当前位置: 代码迷 >> 综合 >> 【转】antd 踩坑之select的placeholder不显示问题
  详细解决方案

【转】antd 踩坑之select的placeholder不显示问题

热度:22   发布时间:2023-12-21 06:17:28.0

在antd中 使用form去回显或者新增表单数据时,select的placeholder不显示

如下例子:新增的时候,默认地址是空 “” 或者 null, 都不好使

<FormItemlabel="所属网点"{...formItemLayout}>{getFieldDecorator("bankId", {initialValue: this.props.type=== "edit" ? this.props.data.bank.id : "",rules: [{ required: true, message: "请选择所属网点!" }],})(<Selectplaceholder="请选择所属地点">{branchArr.map(v => {return (<Select.Optionvalue={v.id}key={v.id}>{v.branchName}</Select.Option>)})}</Select>)}</FormItem>

这里就要主要了,form中的select初始值为空时 要用 undefined

换成如下这样就OK了

initialValue: this.props.isTrue ? this.props.data.bank.id : undefined,

注意,form中的日期datePicker相关的日期的空,初始值要用 null

  相关解决方案