简体   繁体   English

完整的日历插件不会删除事件

[英]full calendar plugin not removing events

i'm using full calendar plugin v3 . 我正在使用完整的日历插件 v3。 the problem is removeEventSource function does not work when i specify parameter. 问题是我指定参数时removeEventSource函数不起作用。 i've tried to put Id, URL as parametres, and use refetchEvents but no luck. 我试图将Id,URL作为参数,并使用refetchEvents但没有运气。

$('#calendar').fullCalendar( 'removeEventSource'); //working without parameters

$('#calendar').fullCalendar( 'removeEventSource', 1); //does not work

array: 数组:

var  events = [
            {    id: 1,

                title: 'dinner',
                start: '2016-09-14',
                end: '2016-09-14'
            },
            {    id: 2,
                title: 'All Day Event',
                start: '2016-09-10',
                end: '2016-09-10'
            },
            {   id: 3,
                title: 'Long Event',
                start: '2016-09-10',
                end: '2016-09-10'
            },
            {   id: 4,
                title: 'Repeating Event',
                start: '2016-09-09T16:00:00',
                end: '2016-09-09'
            }
        ]

intilize the calendar 利用日历

 var calender = $('#calendar').fullCalendar({
    header: {
    left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        defaultDate: '2016-09-12',
        navLinks: true, 
        selectable: true,
        droppable: true,
        selectHelper: true,
        select: function(start, end) {
            var title = prompt('Event Title:');
            var eventData;
            if (title) {
                eventData = {
                    title: title,
                    start: start,
                    end: end
                };
                $('#calendar').fullCalendar('renderEvent', eventData, true); 
            }
            $('#calendar').fullCalendar('unselect');
        },
        drop: function() {
            if ($('#drop-remove').is(':checked')) {
                $(this).remove();
            }
        }
        ,
        editable: true,
        eventLimit: true, 
        events :  events
    });

click event 点击事件

$('body').on('click','.fc-close',function(e){
    //alert('remove event');
    $('#calendar').fullCalendar( 'removeEventSource', 1);
    $('#calendar').fullCalendar( 'refetchEvents' );



    });

You are a bit confused over eventSources and events , an evenSource is a collection of events so when you pass that events in the initialization a default eventSource is initialized with no id that's why it's only working when you don't pass any id.Correct way to pass eventSource is embed you events inside it and give an id to each eventSource item like below 您对eventSourcesevents有点困惑,evenSource是事件的集合,因此当您在初始化中传递events默认的eventSource会被初始化为不带id ,这就是为什么仅在不传递任何id情况下它才起作用的原因。传递eventSource会将事件嵌入其中,并为每个eventSource项提供一个ID,如下所示

var eventSrc = [
                 {  
                    id:1,
                    events : [{                             
                                id: 1,
                                title: 'dinner',
                                start: '2016-09-14',
                                end: '2016-09-14'
                              },
                              {    
                                id: 2,
                                title: 'All Day Event',
                                start: '2016-09-10',
                                end: '2016-09-10'
                             }]
                 },
                 {  
                    id:2,
                    events : [{                                 
                                id: 1,
                                title: 'camping',
                                start: '2016-08-14',
                                end: '2016-08-14'
                              },
                              {    
                                id: 2,
                                title: 'sports day',
                                start: '2016-08-10',
                                end: '2016-08-10'
                             }]
                 }
               ]

In initialization 在初始化中

var calender = $('#calendar').fullCalendar({
                                            //other stuff
                                            eventSources : eventSrc
                                          });

Now just pass id of eventSource to remove it 现在只需传递eventSource的ID即可将其删除

$('#calendar').fullCalendar( 'removeEventSource', 1);

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

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