123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import React from 'react';
- import { Select } from 'antd';
- const Yearselect = React.createClass({
- getInitialState: function () {
- return { theOption: [] };
- },
- onChange(e) {
- this.props.handleyear(e);
- this.setState({
- Year: e
- });
- },
- componentWillMount() {
- const Option = Select.Option;
- const d = new Date();
- const thisYear = d.getFullYear();
- this.state.thisYear = d.getFullYear();
- for (let i = thisYear; i >= 1950; i--) {
- this.state.theOption.push(<Option key={i.toString()}>{i}</Option>)
- };
- this.state.defYear = this.state.thisYear.toString();
- },
- componentWillUpdate(nextProps) {
- if (this.props.defValue != nextProps.defValue) {
- this.state.Year = nextProps.defValue;
- };
- },
- render() {
- return (
- <Select value={this.state.Year} className="year-select"
- placeholder="请选择年份"
- style={{ width: 200 }}
- onChange={this.onChange}>
- {this.state.theOption}
- </Select>
- )
- }
- });
- export default Yearselect;
|