我在React.js中为Datepicker编写了一个代码,但它无法正常工作:
var DatePicker = React.createClass({
getInitialState: function () {
return {
currentDate: Moment().format('MM/DD/YYYY')
};
},
prev: function () {
var dateForHandler = new Date(this.state.currentDate);
var dateForState = new Date(this.state.currentDate);
this.props.dateHandler(dateForHandler.setDate(dateForHandler.getDate() - 7));
this.setState({currentDate: Moment(dateForState.setDate(dateForState.getDate() - 7)).format('MM/DD/YYYY')});
},
next: function () {
var dateForHandler = new Date(this.state.currentDate);
var dateForState = new Date(this.state.currentDate);
this.props.dateHandler(dateForHandler.setDate(dateForHandler.getDate() + 7));
this.setState({currentDate: Moment(dateForState.setDate(dateForState.getDate() + 7)).format('MM/DD/YYYY')});
},
render: function () {
var currentDate = this.state.currentDate;
return (
<div className="col-md-12 text-center mar_top_bottom">
<Button text="" key="prev" click={this.prev} css="arrow_icon_backg arrow_left_icon pull-left"/>
<p className="text_padding">{Moment().format('MM/DD/YYYY')==currentDate?'This Week':'Week of '+currentDate}</p>
<Button text="" key="next" click={this.next} css="arrow_icon_backg arrow_right_icon pull-right"/>
</div>
);
},
componentDidMount: function () {
},
componentWillUnmount: function () {
}
我创建了一个contrl DatePicker.js。上面的代码写在DatePicker.js上。
我在js页面上调用此datepicker,然后datepicker将不会来。