【问题标题】:How can I color a specific day with specific time with slotPropGetter of react-big-calendar?如何使用 react-big-calendar 的 slotPropGetter 为特定时间的特定日期着色?
【发布时间】:2020-03-21 20:40:18
【问题描述】:

我有一个react-big-calendar,我想获得相同的信息,例如日期、开始和结束(作为时间),以便使用 slotPropGetter 为时间和日期槽着色。

我的后台信息是:

    {   "start": "2019-08-23T13:30:00",
        "end": "2019-08-23T18:00:00",
        "rendering": "background",
        "color": "#f740f7"
    }

我尝试使用slotPropGetter

slotPropGetter={
                (date) => {
                    for(let i =0; i<this.state.eventsPlanning.length; i++) {
                      if(this.state.eventsPlanning[i].rendering === 'background') {
                        let newStyle ={
                          backgroundColor:'red'
                        }
                        return {
                          className: "rbc-day-slot rbc-time-slot",
                          style: newStyle
                        }
                      }
                    }
                  }
                }

当我运行它时,似乎所有的日子都被着色了,但我只想根据信息的startend着色。

我该如何解决这个问题?

【问题讨论】:

    标签: javascript reactjs fullcalendar react-big-calendar


    【解决方案1】:

    DayWeek 视图中渲染每个timeslot 时调用slotPropGetter 方法,传递的date 对象是完整的日期/时间js Date 对象插槽的开始时间。在这些视图中,每小时长块调用此方法的次数取决于您日历的steptimeslots 属性。因此,例如,默认的step30timeslots2,这将传递一个日期与HH:00HH:30 它被调用两次(HH 是实际的 24小时hour)。如果您将其更改为15step4timeslots,则该方法将每小时调用四次,每次递增十五分钟。您必须使用自己的日期数学来确定正在调整哪些槽单元格。

    【讨论】:

    • 谢谢@史蒂夫
    猜你喜欢
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多