Fullcalendar每天两个活动

时间:2017-11-07 14:01:45

标签: php fullcalendar

我正在使用JavaScript事件日历。可定制和开源。 https://fullcalendar.io/

是否可以在fullcalendar中每天设置最多两个事件?

我知道可以只设置一个事件。

1 个答案:

答案 0 :(得分:0)

当在日历上删除外部事件并且已呈现外部事件时,将运行eventReceive回调。发生这种情况时,我们可以使用“clientEvents”方法检查外部事件被删除当天已经存在多少事件,并在此基础上决定是否将其从日历中删除。

eventReceive: function(event) {
  var newEventDay = event.start.startOf('day');
  var existingEvents = $("#calendar").fullCalendar("clientEvents", function(evt) {
    //this callback will run once for each existing event on the current calendar view
    //if the event has the same start date as the new event, include it in the returned list (to be counted)
    if (evt.start.startOf('day').isSame(newEventDay)) {
      return true;
    } else {
      return false;
    }
  });

  //if this new event means there are now more than 2 events on that day, remove this new event again (N.B. we must do it like this because by this point the event has already been rendered on the calendar)
  if (existingEvents.length > 2) $("#calendar").fullCalendar("removeEvents", function(evt) {
    if (evt == event) return true;
  });
}

N.B。这假设您拖动的事件不会超过一天。如果可以的话,你需要稍微改变一下这个代码,并将结束日期也纳入等式中。

您可以在此处查看一个有效的示例:http://jsfiddle.net/Lfm1odm1/2/