您可以遍历范围内的天数并使用包含的天数填充数组:
let daysList = [];
if (range.from && range.to) {
daysList = [range.from];
while (daysList[daysList.length - 1] < range.to) {
let day = daysList[daysList.length - 1];
let dayToAdd = new Date(day.getFullYear(), day.getMonth(), day.getDate() + 1);
if (!isDisabled(dayToAdd)) { // here check if the day is disabled
daysList.push(dayToAdd);
}
}
daysList.pop();
}
console.log("Selected days:", daysList)
使用范围示例查看此代码框。
您需要实现自己的isDisabled
功能(这取决于您存储禁用日期的位置),可能是这样的:
disabledDays=[] // your array of disabled days
function isDisabled(day) {
return disabledDays.find(disabledDay =>
DateUtils.isSameDay(day, disabledDay)
)
}