Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 传入所选日期时,react datepicker不可编辑_Reactjs_React Datepicker - Fatal编程技术网

Reactjs 传入所选日期时,react datepicker不可编辑

Reactjs 传入所选日期时,react datepicker不可编辑,reactjs,react-datepicker,Reactjs,React Datepicker,使用react datepicker并传入日期时,我无法编辑日期 _updateStartDate = (value) => { this.setState({ startDate: value }); } <DatePicker selected={startDate ? moment(startDate, 'DD-MM-YYYY') : moment()} onSelect={(value) => {this._updateStar

使用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')) }}
 />
\u updateStartDate=(值)=>{
this.setState({startDate:value});
}
{this.\u updateStarDate(矩(值).format('YYYY-MM-DD HH:MM:ss'))}
onChange={(value)=>{this.\u updatestardate(moment(value).format('YYYY-MM-DD HH:MM:ss'))}
/>

你好像有点打字错误

您的意思是引用此.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')) }}
 />
{this.\u updateStarDate(矩(值).format('YYYY-MM-DD HH:MM:ss'))}
onChange={(value)=>{this.\u updatestardate(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')) }}
          />);  } 
\u renderEffectiveStartDateCell=(startDate)=>{
返回({this.\u updateStartDate(矩(值).format('YYYY-MM-DD HH:MM:ss'))}
onChange={(value)=>{this.\u updatestardate(moment(value).format('YYYY-MM-DD HH:MM:ss'))}
/>);  } 
这将允许datepicker使用传入的startDate或仅当当前日期为nothing时才传入


如果不将此值作为参数传入,您将无法定义startDate。

您是否从状态对象解构了
startDate
??因为从三元运算符来看,它总是求助于
moment()
,因为
startDate
将是
未定义的