Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
701 views
in Technique[技术] by (71.8m points)

php - Fullcalendar two events per day

I′m using A JavaScript event calendar. Customizable and open source. https://fullcalendar.io/

Is it possible to set a maximum of two events per day in fullcalendar?

I know that it is possible to set only one event.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The eventReceive callback runs when an external event is dropped on the calendar and has been rendered. When this happens we can use the "clientEvents" method to check how many events are already present on the day the external event was dropped on, and decide on that basis whether to remove it from the calendar.

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. This assumes that the events you're dragging don't span more than one day. If they can, you'll need to alter this code a bit and bring the end date into the equation as well.

You can see a working example here: http://jsfiddle.net/Lfm1odm1/2/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...