【问题标题】:how to clear the values in react-multiple-datepicker?如何清除 react-multiple-datepicker 中的值?
【发布时间】:2018-08-01 23:10:27
【问题描述】:

我正在使用 react-multiple-datepicker。但我无法清除分配后的值。
从“react-multiple-datepicker”导入 MultipleDatePicker; 从“反应”导入反应;

class Addjob extends React.Component {
    constructor(props) {
        super(props);
        this.state ={
        selectedDays:[]
        };
        this.displayDates=this.displayDates.bind(this);
    }

    displayDates(dates) {
        console.log("selected dates:"+ dates);
        console.log(typeof dates);     
        dates.forEach(function(x) {
            var d = new Date(x),
            month = '' + (d.getMonth() + 1),
            day = '' + d.getDate(),
            year = d.getFullYear();    
            if (month.length < 2) month = '0' + month;
            if (day.length < 2) day = '0' + day;
            console.log(year);
            console.log(day);
            console.log(month);
            y.push([year, month, day].join('-'));
            a=JSON.stringify(y);
            a=a.replace("[","");
            a=a.replace("]","");
            a=a.replace(/\"/g, "")  ; 
        });
        this.setState({selectedDays:a});
    }
    render() {
        return(
            <MultipleDatePicker className="multipicker" onSubmit={this.displayDates} id="multidatepicker"/>                                 
        );
    }
}

【问题讨论】:

  • 能否提供更多代码。你是如何设置日期值的?

标签: javascript node.js html reactjs css


【解决方案1】:

我认为你应该试试这个: - 在渲染中:

 render() {
        return(
                <>
                    <MultipleDatePicker className="multipicker" onSubmit={this.displayDates} 
                             id="multidatepicker"/>
                    <Button onClick={(e)=>ClearDate(e)}>Clear</Button>       
                </>                 
        );
    }

然后函数:

ClearDate = (e) => {
   e.preventDefault();
   this.setState({selectedDays:[]});
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-05
    • 2014-04-07
    • 2011-08-08
    • 2020-03-29
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多