yearSelect.jsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import { Select } from 'antd';
  3. const Yearselect = React.createClass({
  4. getInitialState: function () {
  5. return { theOption: [] };
  6. },
  7. onChange(e) {
  8. this.props.handleyear(e);
  9. this.setState({
  10. Year:e
  11. });
  12. },
  13. componentWillMount() {
  14. const Option = Select.Option;
  15. const d = new Date();
  16. const thisYear = d.getFullYear();
  17. this.state.thisYear = d.getFullYear();
  18. for (let i = thisYear; i >= 1950; i--) {
  19. this.state.theOption.push(<Option key={i.toString()}>{i}</Option>)
  20. };
  21. this.state.defYear = this.state.thisYear.toString();
  22. },
  23. componentWillUpdate(nextProps){
  24. if ( nextProps.defValue ) {
  25. this.state.Year = nextProps.defValue;
  26. };
  27. },
  28. render() {
  29. return (
  30. <Select value={this.state.Year} className="year-select" onChange={this.onChange}>
  31. {this.state.theOption}
  32. </Select>
  33. )
  34. }
  35. });
  36. export default Yearselect;