简体   繁体   English

FullCalendar 结束时间

[英]FullCalendar end time

I am not sure what I am doing wrong.我不确定我做错了什么。 I am testing fullcalendar.js and would like to display slots with start and end times.我正在测试 fullcalendar.js 并希望显示带有开始和结束时间的插槽。 I am inserting the end time, I have also set the allDay flag to false.我正在插入结束时间,我还将 allDay 标志设置为 false。 Yet, I do not get the end time displayed.但是,我没有显示结束时间。

class TimeTable {
  constructor(title, start, end,startStr, endStr, allDay, extendedProps) {
    this.title = title;
    this.start = start;
    this.end = end;
    this.startStr = startStr;
    this.endStr = endStr;
    this.allDay = allDay;
    this.extendedProps = extendedProps;
  }
}

class extendedProps {
    constructor(moduleName, lecturer, room, campus){
    this.moduleName = moduleName;
    this.lecturer = lecturer;
    this.room = room;
    this.campus = campus;
  }
}


details = [{"moduleCode":"AS007",
           "moduleName":"The Art of Spycraft",
       "start":"2022-01-05T10:30:00",
           "end":"2022-01-05T12:30:00",
           "lecturer":"James Bond",
           "room":"007",
           "campus":"A"
           },
       {"moduleCode":"AS007",
           "moduleName":"The art of Spycraft",
       "start":"2022-01-05T14:30:00",
           "end":"2022-01-05T15:30:00",
           "lecturer":"James Bond",
           "room":"007",
           "campus":"A"
           }
       ]

function constructTimetableArray(details){
    let eventsObject = [];
  for(let i = 0; i < details.length; i++){
    var e = new extendedProps(details[i].moduleName, details[i].lecturer, details[i].room, details[i].campus);
    var stDate = new Date(details[i].start);
    var edDate = new Date(details[i].end);
    var t = new TimeTable(details[i].moduleCode, stDate, edDate,details[i].start, details[i].end, false, e);
    eventsObject.push(t);
  }
    return eventsObject;
}

  document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');
        var eventsData = {"events":constructTimetableArray(details)}
        console.log(eventsData);
        var calendar = new FullCalendar.Calendar(calendarEl, {
          events: eventsData,
  initialView: 'dayGridWeek'
        });
        calendar.render();
      });

What am I missing, is it incorrect formatting?我错过了什么,格式不正确吗?

Whether the end times are displayed on the calendar for your events depends on活动的结束时间是否显示在日历上取决于

  1. The view you're using, and/or您正在使用的视图,和/或

  2. the value of the displayEventEnd calendar setting. displayEventEnd日历设置的值。

As the documentation says, the default values for this are:正如文档所说,默认值为:

false // for dayGridMonth and dayGridWeek views false // 对于 dayGridMonth 和 dayGridWeek 视图

true // for timeGridWeek, timeGridDay, and dayGridDay true // 对于 timeGridWeek、timeGridDay 和 dayGridDay

So since you're using dayGridWeek as your initial view, end times are hidden by default.因此,由于您使用 dayGridWeek 作为初始视图,因此默认情况下会隐藏结束时间。

You can either switch them on across all views by adding您可以通过添加在所有视图中打开它们

displayEventEnd: true

to your calendar options, or you can set it per-view using View-Specific Options .到您的日历选项,或者您可以使用View-Specific Options为每个视图设置它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM