简体   繁体   English

FullCalendar JS(没有事件时添加事件)

[英]FullCalendar JS (Add event when there's no event)

I'm trying to find a way to put an event when there's no even on that specific date. 我正在尝试寻找一种方法来在特定日期甚至没有活动时进行活动。

So example: 这样的例子:

I have rendered my Calendar but there's 2 days that doesn't have an event. 我已经绘制了日历,但是有2天没有任何活动。 So on those day I want to put add an event that says "Closed". 因此,在那一天,我想添加一个显示“已关闭”的事件。 I have tried multiple thing but can't find a way that works.... 我已经尝试了多种方法,但是找不到可行的方法。

This is my code for now: 这是我现在的代码:

$('#calendar').fullCalendar({
        editable: false,
        events: event,
        firstDay: 1,
        eventRender: function (event, element, view) {
            $(element).tooltip({ title: event.description });
            $(element).each(function () { $(this).addClass('dateClass-' + event.start.date().toString()); $(this).attr('date-num', event.start.date().toString()); });
            if (view.name == "month") {

                console.info("DATE: " + event.start.date().toString());

                /*$('.fc-month-view').find('.fc-day-number').each(function () {
                    CellDates.push($(this).text());
                    if ($('table').hasClass('.dateClass-' + $(this).text())) {
                        console.info("Got an event!");
                    } else {
                        console.info("No event on that day!");
                    }
                });*/

                for (var i = 0; i < 40; i++) {
                    if ($(element).hasClass('dateClass-' + i)) {
                        console.info("Event: " + event.start.year().toString() + "-" + event.start.month().toString() + "-" + event.start.date().toString());
                    } else {
                        console.info("No Event: " + event.start.year().toString() + "-" + event.start.month().toString() + "-" + event.start.date().toString());
                        var _date = event.start.year().toString() + "-" + event.start.month().toString() + "-" + event.start.date().toString()
                        var _event = [{ "title": "Closed", "start" : _date}];
                        $('#calendar').fullCalendar('addEvent', _event)
                    }
                }

            }
        }
    });

It doesn't seems to work... If you guys could help me to find a solution for that. 它似乎不起作用...如果你们可以帮助我找到解决方案。 I need to display closed to any days that doesn't have any event on any month. 我需要在任何月份没有任何活动的任何天关闭显示。

Thanks a lot for your help! 非常感谢你的帮助!

My approach would be to use an array in the View Render Callback. 我的方法是在View Render Callback中使用数组 representing the days in the month. 代表当月的日子。 Create it in your page load script. 在页面加载脚本中创建它。 Reset it in the callback. 在回调中将其重置。

calendarDays = [];

In the Event Render Callback I would look at each event and set the corresponding position in the array to true. 事件渲染回调中,我将查看每个事件并将数组中的相应位置设置为true。

calendarDays[event.date()] = true;

In the Event After All Render Callback I would look at how many days are in the month. 在“ 所有渲染后回叫事件”中,我将查看一个月中有多少天。 For each day check the corresponding position in the array. 每天检查阵列中的相应位置。 If it does not exist, you don't have an event for the day and you can add a new one. 如果不存在,则表示您当天没有活动,可以添加一个新活动。

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

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