传递选定日期时,react-datepicker 不可编辑
react-datepicker not editable when passing in selected date
当使用 react-datepicker 并传入日期时,我无法编辑日期。
_updateStartDate = (value) => {
this.setState({ startDate: value });
}
<DatePicker
selected={startDate ? moment(startDate, 'DD-MM-YYYY') : moment()}
onSelect={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
onChange={(value) => { this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
/>
你好像有点错别字
您是要参考 this.state.startDate
吗?
<DatePicker
selected={this.state.startDate ? moment(this.state.startDate, 'DD-MM-YYYY') : moment()}
onSelect={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
onChange={(value) => { this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
/>
未定义开始日期。如果你传递这个,你可能想尝试这样的事情。
_renderEffectiveStartDateCell = (startDate) => {
return (<DatePicker
selected={startDate ? moment(startDate, 'DD-MM-YYYY') : moment()}
onSelect={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
onChange={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
/>); }
这将允许日期选择器使用传入的 startDate 或只传入当前日期。
如果不将此值作为参数传递,您将得到 undefined for startDate。
当使用 react-datepicker 并传入日期时,我无法编辑日期。
_updateStartDate = (value) => {
this.setState({ startDate: value });
}
<DatePicker
selected={startDate ? moment(startDate, 'DD-MM-YYYY') : moment()}
onSelect={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
onChange={(value) => { this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
/>
你好像有点错别字
您是要参考 this.state.startDate
吗?
<DatePicker
selected={this.state.startDate ? moment(this.state.startDate, 'DD-MM-YYYY') : moment()}
onSelect={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
onChange={(value) => { this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
/>
未定义开始日期。如果你传递这个,你可能想尝试这样的事情。
_renderEffectiveStartDateCell = (startDate) => {
return (<DatePicker
selected={startDate ? moment(startDate, 'DD-MM-YYYY') : moment()}
onSelect={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
onChange={(value) => {this._updateStartDate(moment(value).format('YYYY-MM-DD HH:mm:ss')) }}
/>); }
这将允许日期选择器使用传入的 startDate 或只传入当前日期。
如果不将此值作为参数传递,您将得到 undefined for startDate。