【问题标题】:Combine off days, past days and array of customized days to be disabled in day-picker结合休息日、过去几天和自定义日期数组以在日期选择器中禁用
【发布时间】:2020-04-14 17:23:44
【问题描述】:

我是 reactjs 新手。我想就如何使用以下标准禁用 react-day-picker 上的天数寻求一些指导:

  1. 休息日
  2. 过去的日子
  3. 日期数组(在后端获取)

示例代码:

const selectedDays = [new Date(2020,01,01), new Date(2020,01,02)]

< DayPicker disabledDays={[{ daysOfWeek: dayOffs }, {before: new Date()}, selectedDays]} >

非常感谢任何帮助:)

【问题讨论】:

    标签: javascript reactjs react-day-picker


    【解决方案1】:

    从服务器检索到的日期很可能不是日期对象,因此需要转换它们(使用 map 函数)。然后需要将它们合并到数组中(...展开运算符)。

    < DayPicker disabledDays={[{ daysOfWeek: dayOffs }, {before: new Date()}, ...selectedDays.map(day=>new Date(day))]} >
    

    【讨论】:

    • 您好,非常感谢您抽出宝贵时间帮助我 :) 抱歉,但我忘记告诉您 selectedDays 已经是转换后的日期数组。我还尝试使用模拟数据来确保 const selectedDays = [new Date(2020,3,20), new Date(2020,3,22)];
    • 只需将地图替换为 ...selectedDays。它应该工作
    • 您好,我已经尝试过了,但它不起作用 const selectedDays = [new Date(2020,3,20), new Date(2020,3,22)]; disabledDays={[{ daysOfWeek: dayOffs }, {before: today}, selectedDays]}
    • disabledDays={[{ daysOfWeek: dayOffs }, {before: today}, ...selectedDays]}
    • 或 disabledDays={[{ daysOfWeek: dayOffs }, {before: today}].concat(selectedDays)}
    猜你喜欢
    • 1970-01-01
    • 2021-04-15
    • 2016-07-03
    • 2013-03-23
    • 2021-01-11
    • 2018-10-16
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    相关资源
    最近更新 更多