【发布时间】:2020-09-11 18:46:06
【问题描述】:
我正在尝试使用react-big-calendar 在日历中显示一组数据。以下是我要显示的数据。由于某种原因,它没有显示任何数据。我能够在单个事件中进行硬编码,但我希望能够映射我的数据并显示我的所有 7 个事件。 events 是日历获取其数据以显示的位置。我尝试将其更改为events:{data},但最终没有结果。
this.state.interview_dates:
0: {start: Wed Sep 16 2020 17:00:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 17:15:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"},
1: {start: Wed Sep 16 2020 17:15:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 17:30:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"},
2: {start: Wed Sep 16 2020 17:30:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 17:45:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"},
3: {start: Wed Sep 16 2020 17:45:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 18:00:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"},
4: {start: Wed Sep 16 2020 18:00:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 18:15:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"},
5: {start: Wed Sep 16 2020 18:15:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 18:30:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"},
6: {start: Wed Sep 16 2020 18:30:00 GMT-0700 (Pacific Daylight Time), end: Wed Sep 16 2020 18:45:00 GMT-0700 (Pacific Daylight Time), title: "30 minutes"}
我的代码:
var start_date = new Date("2020-09-09 18:00:00");
start_date.toString();
var end_date = new Date("2020-09-09 19:00:00");
end_date.toString();
class SchedulePage extends Component {
constructor(props) {
super(props);
this.state = {
events: [
{
start: start_date,
end: end_date,
title: "15 minute interview",
},
],
};
}
render() {
if (this.state.interview_dates === undefined) {
return null;
}
const data = this.state.interview_dates.map((item) => {
return {
start: item.start,
end: item.end,
title: item.title,
};
});
console.log(data);
return (
<div className="calendar-container">
<Calendar
localizer={localizer}
views={["month", "week"]}
defaultDate={new Date()}
defaultView="week"
events={this.state.events}
style={{ height: "100vh" }}
onSelectEvent={this.test}
step={15}
min={new Date(2020, 1, 0, 6, 0, 0)}
max={new Date(2020, 1, 0, 23, 0, 0)}
/>
<ScheduleInterview
onClose={this.showCreateInterview}
show={this.state.createInterview}
/>
</div>
);
}
【问题讨论】:
标签: javascript reactjs jsx react-big-calendar