Fullcalendar V4重新加载事件。removeEventSource不';不存在

Fullcalendar V4重新加载事件。removeEventSource不';不存在,fullcalendar,fullcalendar-4,Fullcalendar,Fullcalendar 4,我试图在我的网站上添加日历,但我不知道如何从ajax源重新加载事件。在以前的版本中,您可以删除事件源,添加nwe源并重新绘制日历,但是在这个版本中,我在文档中读到它只有addEventSource事件 我有一个不好的解决方案,在绘制之前取消日历的顺序(如果存在),但我会丢失显示的视图和日期。这不是一个好的解决办法 这是我的密码: var calendar; var startDateSelected; //YYY-MM-DD var endDateSelected; //YYY-MM-D

我试图在我的网站上添加日历,但我不知道如何从ajax源重新加载事件。在以前的版本中,您可以删除事件源,添加nwe源并重新绘制日历,但是在这个版本中,我在文档中读到它只有
addEventSource
事件

我有一个不好的解决方案,在绘制之前取消日历的顺序(如果存在),但我会丢失显示的视图和日期。这不是一个好的解决办法

这是我的密码:

var calendar;
var startDateSelected;  //YYY-MM-DD
var endDateSelected;    //YYY-MM-DD
var evTittleSelected;

//Example data
function getCalendarEvents() {
    return [{
        title: 'example1',
        start: '2019-07-15 12:00:00'
    }, {
        title: 'Example2',
        start: '2019-07-06 12:00:00',
        end: '2019-07-10 18:00:00'
    }];
}

document.addEventListener('DOMContentLoaded', function () {
    drawCalendar();
});

function drawCalendar() {
    var events = getCalendarEvents();
    var calendarEl = document.getElementById('calendar');
    if(calendar != undefined) calendar.destroy();
    calendar = new FullCalendar.Calendar(calendarEl, {
    plugins: ['interaction', 'dayGrid', 'timeGrid'],
        locale: 'es',
        selectable: true,
        editable: true,
        header: {
            left: 'prevYear,prev,next,nextYear today',
            center: 'title',
            right: 'dayGridMonth,timeGridWeek,timeGridDay'
        },
        select: function (info) {
            startDateSelected = moment(info.startStr).format("DD-MM-YYYY HH:mm:ss");
            endDateSelected = moment(info.endStr).format("DD-MM-YYYY HH:mm:ss");
            alert('de ' + startDateSelected + ' a ' + endDateSelected);
        },
        eventClick: function(info) {
            evTittleSelected = info.event.title;
            startDateSelected =  moment(info.event.start).format("DD-MM-YYYY HH:mm:ss");
            endDateSelected =  moment(info.event.end).format("DD-MM-YYYY HH:mm:ss");
            alert('de ' + startDateSelected + ' a ' + endDateSelected);
        },
        events: events
    });
    calendar.render();
}
我尝试如下更改事件源:

calendar.destroy();
calendar.addEventSource( events );
calendar.refetchEvents();
calendar.render();
但是如果没有
removeEventSource
方法,它只会将新事件添加到日历中

那么有什么方法可以重新加载事件吗

新内容用于输入答案(并在评论中使用解决方案):

我尝试按照以下两种方式实现事件提要: fullcalendar.io/docs/events-json-feed或 fullcalendar.io/docs/events-function

当我将从ajax调用接收到的事件直接放入我的nodejs服务器时,它会加载所有事件(没有好的重新加载选项)。所以我的events对象的格式似乎还可以

我使用这个ajax请求

jQuery.ajax({
    type: 'POST',
    url: '/calendar/getCalendarEvents',
    data: {
        token: localStorage.token
    },
}).then(function success(events) {
    return events;
}, function error(err) {
    console.log(err);
})
以此格式填充事件的步骤

events:  [{ 
    id: 1,
    title: 'others',
    start: '2019-07-12 00:00:00',
    end: '2019-07-15 00:00:00',
    color: '#a6a6a6' 
}, { 
    id: 2,
    title: 'any',
    start: '2019-07-12 00:00:00',
    end: '2019-07-15 00:00:00',
    color: '#4222C3'
}]
当我尝试使用
事件函数时
出现错误:
回调不是函数错误

events: function(start, end, timezone, callback) {
    jQuery.ajax({
        type: 'POST',
        url: '/calendar/getCalendarEvents',
        data: {
            token: localStorage.token
        },
        success: function(events) {
            callback(events);
        }
    });
}   
使用metod events json提要,解析json时出现错误
失败
,但格式与第一个方法相同(有效)


那么,我会做错什么呢?

正如@ADyson评论的那样,这种解决方案很好:

var eventSources = calendar.getEventSources();
eventSources[0].remove();
calendar.addEventSource(events);
calendar.refetchEvents();
这个想法是要知道
eventSources
是一个数组

但使用这些方法可能会更好: 或


使用:
calendar.refetchEvents()重新加载事件

若要删除事件源,必须首先获取事件源,然后才能针对源本身运行该方法,但无论如何,如果您希望在需要新事件时自动从服务器获取动态事件源(并且可以按需轻松重新访问),按照或(取决于调用服务器的复杂程度)实现事件提要可能更简单,如果您需要一些帮助,您可以随时向我们展示代码:-)您似乎已经根据fullCalendar版本3的方式定义了您的函数。检查我上面给你的链接()包含最新的文档。你会看到签名是与众不同的我找到了一个旧的sintax好的非常感谢
var eventSources = calendar.getEventSources();
eventSources[0].remove();
calendar.addEventSource(events);
calendar.refetchEvents();
events: function(fetchInfo, successCallback, failureCallback) {
    jQuery.ajax({
        type: 'POST',
        url: '/calendar/getCalendarEvents',
        data: {
            token: localStorage.token
        },
        success: function(events) {
            successCallback(events);
        }
    });
}