如何在 FullCalendar.js 中的新事件源之后调用事件方法?

How to call events method after new event source in FullCalendar.js?

我正在尝试为事件创建一个客户端过滤器,我采用了与 addEventSource 相同的方法。我使用 events 方法有条件地呈现事件。我只想知道如何调用 events 方法甚至重新定义它?

这是我用来呈现日历的初始代码

        $('#calendar').fullCalendar({
            header: {                                                                                                                                          
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay'
            },
            displayEventTime: false,
            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: (start, end, timezone, callback) => {
                $.ajax({
                    url: 'get-events',
                    dataType: 'json',
                    data: {
                        // our hypothetical feed requires UNIX timestamps
                        start: start.unix(),
                        end: end.unix()
                    },
                    success: function (res) {
                        console.log(res)
                        var events = [];
                        res.map((value, index) => {
                            if (value.cadence != null) {
                                $("#allDropdown").append(`<a id="file-${value.dq_datafile_id}" onclick="selectThis(this)" href="#about">${value.data_file_name}</a>`)
                            }

                            if (value.cadence == "WEEKLY") {
                                if (value.dqfeed__file_status == "RECEIVED") {
                                    const data_file_name = value.data_file_name;
                                    let repeatDay = dow_handler.hasOwnProperty(data_file_name) ? dow_handler[data_file_name] : undefined

                                    events.push({
                                        title: `${value.data_file_name}`,
                                        start: '2020-04-13',
                                        dow: [repeatDay, 1],
                                        color: '#00ff00'
                                    });
                                }
                           });
                       });
                    });

这是我用来获取新事件或筛选事件的代码

    const applyCalendarFilter = () => {
        var filter = {
            type: 'get',
            url: 'filter-events',
        }
        $("#calendar").fullCalendar('addEventSource', filter);
    }

我收到的错误是 Uncaught TypeError: Cannot read property 'hasTime' of undefined,因为返回的 JSON 没有 start_dateend_date

所以我发现 removeEvents 会清除日历中的所有事件,renderEvents 会接受一个选项参数 events,这会呈现其余事件。

这是执行此操作的代码。

const applyCalendarFilter = () => {
    var filter = {
        type: 'get',
        url: 'filter-events',
    }
    $("#calendar").fullCalendar('removeEvents');
    $.ajax({
            url: 'filter-events',
            type: 'get',
            success: (res) => {
                let events = [];
                res.map((value, index) => {
                    if (value.cadence == "WEEKLY"){
                        events.push({
                            'title': value.title,
                            'start_date': value.start_date,
                            'end_date': value.end_date
                    }
                }) 
                $("#calendar").fullCalendar('renderEvents', events);
            }, error: (res) => {
                alert('cant get the data');
            }
    )};