全日历每天两次活动

编程入门 行业动态 更新时间:2024-10-24 15:15:05
本文介绍了全日历每天两次活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I´m using A JavaScript event calendar. Customizable and open source. 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.

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

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

更多推荐

全日历每天两次活动

本文发布于:2023-11-27 05:18:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636761.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两次   日历

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!