将 react-day-picker 范围限制为 x 天
Limit react-day-picker range to x days
我想将 react-day-picker 中的范围长度限制为例如10天。应该如何完成,包中是否已经有可用的东西?
这是范围选择器的示例:https://react-day-picker.js.org/examples/selected-range/
可以很容易地实现,我刚刚在 handleDayClick 函数中添加了一些行:
而不是这个:
handleDayClick(day) {
const range = DateUtils.addDayToRange(day, this.state);
this.setState(range);
}
实施这个:
handleDayClick(day) {
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const diffDays = Math.round(Math.abs((day - this.state.from) / oneDay));
const range = DateUtils.addDayToRange(day, undefined);
if(diffDays <= 10){
const range = DateUtils.addDayToRange(day, this.state);
this.setState(range);
}
else {
this.setState(range);
}
}
我想将 react-day-picker 中的范围长度限制为例如10天。应该如何完成,包中是否已经有可用的东西?
这是范围选择器的示例:https://react-day-picker.js.org/examples/selected-range/
可以很容易地实现,我刚刚在 handleDayClick 函数中添加了一些行:
而不是这个:
handleDayClick(day) {
const range = DateUtils.addDayToRange(day, this.state);
this.setState(range);
}
实施这个:
handleDayClick(day) {
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const diffDays = Math.round(Math.abs((day - this.state.from) / oneDay));
const range = DateUtils.addDayToRange(day, undefined);
if(diffDays <= 10){
const range = DateUtils.addDayToRange(day, this.state);
this.setState(range);
}
else {
this.setState(range);
}
}