update demo start-end

This commit is contained in:
afc163 2015-10-28 18:35:56 +08:00
parent 735ed1f89f
commit 17afda5028

View File

@ -9,53 +9,45 @@
````jsx ````jsx
var Datepicker = antd.Datepicker; var Datepicker = antd.Datepicker;
var Test = React.createClass({ var DateRange = React.createClass({
getInitialState() { getInitialState() {
return { return {
startValue: null, startValue: null,
endValue: null endValue: null
}; };
}, },
disabledEndDate(endValue) {
if (!endValue || !this.state.startValue) {
return false;
}
return endValue.getTime() <= this.state.startValue.getTime();
},
disabledStartDate(startValue) { disabledStartDate(startValue) {
if (!startValue || !this.state.endValue) { if (!startValue || !this.state.endValue) {
return false; return false;
} }
return startValue.getTime() >= this.state.endValue.getTime(); return startValue.getTime() >= this.state.endValue.getTime();
}, },
disabledEndDate(endValue) {
if (!endValue || !this.state.startValue) {
return false;
}
return endValue.getTime() <= this.state.startValue.getTime();
},
onChange(field, value) { onChange(field, value) {
this.setState({ this.setState({
[field]: value, [field]: value,
}); });
}, },
render() { render() {
var state = this.state; return <div>
return <div style={{width: 240, margin: 20}}> <Datepicker disabledDate={this.disabledStartDate}
<p> value={this.state.startValue}
开始时间: placeholder="开始日期"
<Datepicker disabledDate={this.disabledStartDate} value={state.startValue} onChange={this.onChange.bind(this,'startValue')} />
onChange={this.onChange.bind(this,'startValue')}/> <Datepicker disabledDate={this.disabledEndDate}
</p> value={this.state.endValue}
placeholder="结束日期"
<p> onChange={this.onChange.bind(this,'endValue')} />
结束时间:
<Datepicker disabledDate={this.disabledEndDate} value={state.endValue}
onChange={this.onChange.bind(this,'endValue')}/>
</p>
</div>; </div>;
} }
}); });
ReactDOM.render( ReactDOM.render(
<Test /> <DateRange />
, document.getElementById('components-datepicker-demo-start-end')); , document.getElementById('components-datepicker-demo-start-end'));
```` ````