如何在React的日期选择器中选择今天的日期作为默认日期

时间:2018-10-26 07:45:59

标签: reactjs materialize

页面加载时,react-materialize中是否有任何选项可将今天的日期设置为默认日期?

代码在下面给出

import React,{Component} from 'react';
import { Row, Col, Input, Collapsible, CollapsibleItem } from 'react-materialize';

class MetricsReport extends Component {
    constructor(props) {
      super(props)
      this.state = {
        metricsParams: {fromDate: "", toDate: ""}
      }

      this.handleChangeFromDate = this.handleChangeFromDate.bind(this);
      this.handleChangeToDate = this.handleChangeToDate.bind(this);

    }

    handleChangeFromDate(event) {
      let metricsParams = {...this.state.metricsParams}
      metricsParams.fromDate = event.timeStamp;
      this.setState({metricsParams});
    }
    handleChangeToDate(event) {
      let metricsParams = {...this.state.metricsParams}
      metricsParams.toDate = event.timeStamp; // use event.target.value to get human readable date
      this.setState({metricsParams});
    }


    componentDidMount() {

    }

    render() {

      return (
          <div >
              <label>{'From Date'}</label>
              <Row>
                <Input name='from' type='date' onChange={this.handleChangeFromDate} />
              </Row>
              <label>{'To Date'}</label>
              <Row>
                <Input name='to' type='date' onChange={this.handleChangeToDate} />
              </Row>
          </div>
      )
    }

}

export default MetricsReport;

0 个答案:

没有答案