在日期选择器中启用特定日期
Enable certain dates in a datepicker
我正在 React 中寻找一个只能启用特定日期的日期选择器。所有其他日期都需要禁用。我可以将日期列表传递给日期选择器,它只允许启用此列表中的日期。有谁知道允许这样做的日期选择器吗?
一个例子使用 https://reactdatepicker.com/
const allowedDates = ['2020-06-04', '2020-06-05'];
return (
<DatePicker
filterDate={(d) => allowedDates.includes(moment(d).format('YYYY-MM-DD')) }
/>
)
您可以使用 React Datepicker 中的 includeDates
。用你的日期列表修改它。
<DatePicker
selected={startDate}
onChange={date => setStartDate(date)}
includeDates={[new Date('2020-08-08'), new Date('2020-08-09')]}
/>
我正在 React 中寻找一个只能启用特定日期的日期选择器。所有其他日期都需要禁用。我可以将日期列表传递给日期选择器,它只允许启用此列表中的日期。有谁知道允许这样做的日期选择器吗?
一个例子使用 https://reactdatepicker.com/
const allowedDates = ['2020-06-04', '2020-06-05'];
return (
<DatePicker
filterDate={(d) => allowedDates.includes(moment(d).format('YYYY-MM-DD')) }
/>
)
您可以使用 React Datepicker 中的 includeDates
。用你的日期列表修改它。
<DatePicker
selected={startDate}
onChange={date => setStartDate(date)}
includeDates={[new Date('2020-08-08'), new Date('2020-08-09')]}
/>