简体   繁体   English

使用JQuery的FullCalendar双重事件

[英]FullCalendar Doubling Events using JQuery

Hello I am having a problem using the Full Calendar Library. 您好,我在使用完整日历库时遇到问题。

The events keep doubling ONLY when I hit my custom "Filter" button and change the month. 仅当我按下自定义的“过滤器”按钮并更改月份时,事件才会继续加倍。

When I call the filter I am removing all events and repopulating with the filtered results. 当我调用过滤器时,我将删除所有事件,并使用过滤后的结果重新填充。 The issue looks like when I hit the left/right button it calls the event population again and adds the events. 当我按下左/右按钮时,该问题看起来像它再次调用事件填充并添加事件。 I would like to disable that or rework it. 我想禁用它或对其进行重做。

Here is what is happening: enter image description here 这是正在发生的事情: 在此处输入图像描述

Calendar Code: 日历代码:

function calendarView()
{
    //$('#calendar').fullCalendar('removeEvents')

    var url_str = "/Calendar/GetCalendarEvents"
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next, today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },

        fixedWeekCount: true,
        eventLimit: 4,
        events: url_str,
        eventClick: function (calEvent, jsEvent, view)
        {
            editable: false;
            var currentDate = new Date();
            currentDate.setHours(0, 0, 0, 0);
            if (calEvent.start >= currentDate - 1)
                openEditVisit(calEvent.id)
        }
    });

};

Filter Button Call Code 筛选器按钮呼叫代码

$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/Calendar/GetCalendarEvents",
        data: j,
        async: false,
        dataType: 'json',
        success: function (data) 
        {
            $('#calendar').fullCalendar('removeEvents')
            $('#calendar').fullCalendar('addEventSource', data)

        },
        error: function (xhr, err) {
            alert("ERROR! - readyState: " + xhr.readyState + "<br/>status: " + xhr.status + "<br/>responseText: " + xhr.responseText);
        }
    });

You have a problem because since you already defined events as a JSON feed ( events: url_str ), whenever you change view it will fetch those events without the filter option. 您有一个问题,因为既然您已经将事件定义为JSON提要( events: url_str ),那么无论何时更改视图,它都将获取没有过滤器选项的那些事件。 This is in addition to the filtered events which you previously added as a separate event source. 这是除了你以前添加作为一个单独的事件源过滤的事件。

So a better solution you could use is to utilise the built-in the events-as-a-function feature, and have your custom function take the filter options from your UI into account and send them to the server along with the start/end dates supplied by fullCalendar. 因此,您可以使用的更好的解决方案是利用内置的事件即功能功能,并让您的自定义功能考虑UI中的过滤器选项,并将其与开始/结束一起发送到服务器。 fullCalendar提供的日期。 This would ensure that when you change the view or date, the returned results take your filtering into account, and also don't duplicate the events. 这样可以确保当您更改视图或日期时,返回的结果会考虑您的过滤条件,并且不会重复事件。

Your extra filter button could meanwhile just call "refetchEvents" when clicked, to refresh from the main event source, which is already defined and using the filter options. 同时,您的额外过滤器按钮可以在单击时仅调用“ refetchEvents”,以从主事件源(已定义并使用过滤器选项)刷新。

See https://fullcalendar.io/docs/event_data/events_function/ 参见https://fullcalendar.io/docs/event_data/events_function/

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

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