全日历每天两次活动 [英] Fullcalendar two events per day

查看:91
本文介绍了全日历每天两次活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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.

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

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

这篇关于全日历每天两次活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆