简体   繁体   English

FullCalendar删除外部事件

[英]FullCalendar delete external events

When I'm trying to delete an external event from my calendar, if I add say 3 external events then drag one to the bin, rather than removing just the one event it deletes all events (even the ones from the separate feeds I am doing. 当我尝试从日历中删除一个外部事件时,如果我说3个外部事件,则将其拖到垃圾箱中,而不是仅删除一个事件,它会删除所有事件(甚至是我正在做的单独提要中的事件。

Any idea why this is and how to fix it? 知道这是为什么以及如何解决? Here is the code: 这是代码:

$(document).ready(function () {
    //listens for drop event
    $("#calendarTrash").droppable({
        tolerance: 'pointer',
        drop: function (event, ui) {
            var answer = confirm("Delete Event?")
            if (answer) {
                $('#calendar').fullCalendar('removeEvents', event.id);
            }
        }
    });

    /* initialize the external events  ------------*/
    $('#external-events div.external-event').each(function () {
        // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
        // it doesn't need to have a start or end
        var eventObject = {
            title: $.trim($(this).text()) // use the element's text as the event title
        };

        // store the Event Object in the DOM element so we can get to it later
        $(this).data('eventObject', eventObject);
        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });
    });
});

The event.id in your drop function does not refer to the FullCalendar event. event.iddrop功能不指FullCalendar事件。 It refers to the drop event that was just triggered. 它指的是刚刚触发的放置事件。

You will need to use ui.draggable to access your draggable - in this case the FullCalendar event. 您将需要使用ui.draggable来访问您的可拖动对象-在这种情况下为FullCalendar事件。

Hope this helps! 希望这可以帮助! Cool concept BTW! 酷概念顺便说一句!

Update : Check this fiddle for a proof-of-concept 更新 :检查此小提琴以获得概念证明

For anyone in the same circumstances,.. 对于在相同情况下的任何人,..

 eventDragStop: function(event, jsEvent, ui, view) {

                 if (x) {
                    $('#calendar').fullCalendar('removeEvents', event._id);
                      }

Please notice I am using event._id, x is the result of checking which div the item is dragged into returning a true or false. 请注意,我使用的是event._id,x是检查项目拖动到哪个div返回true或false的结果。 checks which div the event is being dropped into. 检查将事件放入哪个div。 I also had to change some code in fullcalendar.js the function eachEventElement, was causing me an issue with the above code, so I changed it too. 我还必须在fullcalendar.js中更改每个事件元素的代码,导致每个代码出现问题,因此我也进行了更改。

 function eachEventElement(event, exceptElement, funcName) {
    try{
        var elements = eventElementsByID[event._id],
            i, len = elements.length;
        for (i=0; i<len; i++) {
            if (!exceptElement || elements[i][0] != exceptElement[0]) {
                elements[i][funcName]();
            }
        }
    }
    catch(err)
    {}
}

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

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