Basic setup of react-big-calendar events not showing

末鹿安然 提交于 2019-12-11 09:56:38

问题


Im trying to use the react-big-calendar package. http://intljusticemission.github.io/react-big-calendar/examples/index.html

I have the calendar displaying on the page. The pagination is working and I have no errors in my console. However none of my events are showing. Do I have a syntax / format error somewhere?

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>
  )
}

回答1:


Must add height for calendar container element. If you do not add height for calendar container, calendar won't be visible.

Must read the doc for 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>



回答2:


You need to set a height or min height on the calendar:

.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',
    }
]



回答3:


When you create the BigCalendar component you specify

startAccessor="startDate"
endAccessor="endDate"

This tells BigCalendar to look for startDate= and endDate= instead of start= and end= in your event objects. Change your event array to this and it should work fine:

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',
},
];



回答4:


You've set start and end key in dummydata but you're accessing startDate and endDate.

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


来源:https://stackoverflow.com/questions/47710223/basic-setup-of-react-big-calendar-events-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!