反应大日历事件的基本设置未显示

Basic setup of react-big-calendar events not showing

我正在尝试使用 react-big-calendar 包。 http://intljusticemission.github.io/react-big-calendar/examples/index.html

我在页面上显示了日历。分页正常,我的控制台没有错误。但是 none 的事件正在显示。我在某处有语法/格式错误吗?

import React from 'react';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';

BigCalendar.momentLocalizer(moment); // or globalizeLocalizer


const Calendar = props => {
  const dummyEvents = [
    {
      allDay: false,
      end: new Date('December 10, 2017 11:13:00'),
      start: new Date('December 09, 2017 11:13:00'),
      title: 'hi',
    },
    {
      allDay: true,
      end: new Date('December 09, 2017 11:13:00'),
      start: new Date('December 09, 2017 11:13:00'),
      title: 'All Day Event',
    },
  ];
  return (
     <div>
         <BigCalendar
          events={dummyEvents}
          startAccessor="startDate"
          endAccessor="endDate"
        />
     </div>
  )
}

您需要在日历上设置高度或最小高度:

.rbc-calendar {
  min-height: 600px;
}



const dummyEvents = [
    {
      allDay: false,
      end: new Date('December 09, 2017 20:00:00'),
      start: new Date('December 09, 2017 06:00:00'),
      title: 'hi',
    }
]

创建 BigCalendar 组件时指定

startAccessor="startDate"
endAccessor="endDate"

这会告诉 BigCalendar 在您的事件对象中查找 startDate=endDate= 而不是 start=end=。将您的事件数组更改为此,它应该可以正常工作:

const dummyEvents = [
{
  allDay: false,
  endDate: new Date('December 10, 2017 11:13:00'),
  startDate: new Date('December 09, 2017 11:13:00'),
  title: 'hi',
},
{
  allDay: true,
  endDate: new Date('December 09, 2017 11:13:00'),
  startDate: new Date('December 09, 2017 11:13:00'),
  title: 'All Day Event',
},
];

您已在 dummydata 中设置开始和结束键,但您正在访问 startDate 和 endDate。

<BigCalendar
      events={dummyEvents}
      startAccessor='start'
      endAccessor='end' />

必须为日历容器元素添加高度。 如果不为日历容器添加高度,日历将不可见。

必须阅读 react-big-calendar 的文档:https://github.com/intljusticemission/react-big-calendar

.rbc-calendar {
  min-height: 500px ;
}

<div className="rbc-calendar">
     <BigCalendar
      events={dummyEvents}
      startAccessor="startDate"
      endAccessor="endDate"
    />
 </div>