删除外部事件时获取完整日历上的资源 ID

Getting Resource ID on FullCalendar when dropping external event

本文关键字:日历 资源 ID 外部 事件 获取 删除      更新时间:2023-09-26

我使用的是支持资源的FullCalendar jQuery plugin版本。

我正在按照此示例拖入外部事件。

这一切都运行良好,但我找不到一种方法来获取与外部事件拖放到的单元格(天)关联的Resource ID

我正在使用下面的下降功能。

drop: function(date, allDay) { 
    // this function is called when something is dropped
    // retrieve the dropped element's stored Event Object
    var originalEventObject = $(this).data('eventObject');
    // we need to copy it, so that multiple events
    // don't have a reference to the same object
    var copiedEventObject = $.extend({}, originalEventObject);
    // assign it the date that was reported
    copiedEventObject.start = date;
    copiedEventObject.allDay = allDay;
    // render the event on the calendar
    // the last `true` argument determines if the event "sticks" 
    // (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
    $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
    // is the "remove after drop" checkbox checked?
    if ($('#drop-remove').is(':checked')) {
        // if so, remove the element from the "Draggable Events" list
        $(this).remove();
    }
}

请对此提供任何帮助,我将不胜感激。

我也使用FullCalendar的这个分支,当你删除一个事件时,可以获取资源ID,如下所示:

drop: function(date, allDay, test3, test4, resource) {          
    var originalEventObject = $(this).data('eventObject');
    var copiedEventObject = $.extend({}, originalEventObject);
    copiedEventObject.start = date;
    copiedEventObject.allDay = allDay;
    copiedEventObject.resource = resource.id;
    $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
                
    if ($('#drop-remove').is(':checked')) {
        $(this).remove();
    }
}

因此,您应该将参数resource传递给drop函数,并且可以通过调用 resource.id 来获取资源 ID。