不能在rc-time-picker中设置defaultValye。

问题描述 投票:0回答:1

嘿,我正在使用一个叫rc-time-picker的npm包。

[见这里的npm库] https:/www.npmjs.compackagerc-time-picker

所以在编辑我的帖子时,我想从数据库中获取一个 "时间 "字段,这个字段是在添加表单时由这个rc-time-picker包设置的。

现在,当我点击编辑表格时,我想显示这个 "时间 "字段,我从我的数据库中得到的默认值在rc-time-picker输入框中。

我试过这个,但它不工作

存储在mongodb的数据就像

time:"2:02 pm"

得到我的数据后,我做了

this.setstate({time:res.time}) 

                 <TimePicker
                 showSecond={false}
                 defaultValue={this.state.time}
                 className="xxx"
                 onChange={this.onChange}
                 format={format}
                 use12Hours
                 inputReadOnly
                 />
onChange = (value) => {
console.log(value.format(format));
this.setState({ startTimeForLaterSchedule: 
value.format(format),scheduleTimePickerErrorMessage:false });

};

但在输入框中没有任何显示为defaultValue的内容(虽然我可以通过选择时间来改变时间,但我需要先显示时间)。

javascript reactjs timepicker
1个回答
0
投票

Hı ,根据文档,defaultValue的类型是时刻。你有没有尝试将你的时间转换为时刻?

试试这个:

const now = moment().hour(0).minute(0);

  <TimePicker
    showSecond={false}
    defaultValue={now}
    className="xxx"
    onChange={onChange}
    format={format}
    use12Hours
    inputReadOnly
  />
© www.soinside.com 2019 - 2024. All rights reserved.