在我的代码中,我使用了日期范围选取器(https://www.npmjs.com/package/react-date-range)的npm反应组件之一。在我的屏幕上,我有一个应用日期按钮。如果我点击那个按钮,我想打印日期范围值。如何获得onclick范围值?如何在React日期范围选取器中获取开始日期和结束日期值?
var Calendarcomponent = React.createClass({
getInitialState: function(){
this.state = {
'rangePicker' : {},
'linked' : {},
'datePicker' : null,
'firstDayOfWeek' : null,
'predefined' : {},
}
}
handleSelect:function(range){
console.log(range);
},
handleClick:function(range){
console.log(range);
},
render:function(){
var rangePicker = this.state;
var format = 'dddd, D MMMM YYYY';
return (
<div>
<h4>FILTER BY DATE</h4>
<div className="date-range text-center">
<div className="group">
<label>Date range</label>
<input className="inputMaterial" type="text" value={ rangePicker['endDate'] && rangePicker['endDate'].format(format).toString() } required />
</div>
</div>
<div className="set-borrow-dates">
<div id="select-date">Select Borrow date</div>
<DateRange onInit={this.handleSelect} onclick={this.handleClick} />
<button id="apply-dates"><i className="fa fa-check-circle"></i> Apply Dates</button>
</div>
</div>
)
}
});
发布您的代码。 – azium
@azium。我已经更新了代码。你可以请现在检查吗? – Sathya
你可以发表小提琴吗? (使用https://jsfiddle.net或snippet) –