简体   繁体   English

如何在具有时刻范围的反应日期中禁用多个日期

[英]How to disable multiple date in react-dates with moment range

How can I block dates in react-dates airbnb with moment date range?如何在具有时刻日期范围的 react-dates airbnb 中阻止日期?

const BAD_DATES = [
   moment.range('2018-04-15', 'YYYY-MM-DD', '2018-04-27', 'YYYY-MM-DD'),
   moment.range('2018-05-10', 'YYYY-MM-DD', '2018-05-20', 'YYYY-MM-DD'),
];
const isDayBlocked = day => BAD_DATES.filter(d => d.isSame(day, 'day')).length > 0;
return (
  <DateRangePicker
    isDayBlocked={isDayBlocked}
    ...
  />
);

I have not used this component but I think you should like this.我没有使用过这个组件,但我想你应该喜欢这个。

if it passing the selected day to the function -> You should use range.contains(day) in the filter如果它将选定的日期传递给 function -> 您应该在过滤器中使用 range.contains(day)

OR或者

if you passing the selected date range to the function -> you should use range1.overlaps(range2) in the filter如果您将选定的日期范围传递给 function -> 您应该在过滤器中使用 range1.overlaps(range2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM