2012-04-24 77 views
2

我在我的项目中使用Fullcalendar(http://arshaw.com/fullcalendar)。它通过json源获取事件。Javascript Fullcalendar - 复制事件

我想给用户选择复制日历上的一个事件到另一天 - 我想用拖动(嗯,这是客户的要求)。

但拖动似乎是移动一个事件,而不是复制 - 有没有办法让被拖动的事件的“副本”(或复制停留在原始位置),所以它看起来像复制操作?

我试图在eventDragStart回调中复制事件对象,但它不起作用。

+1

IMO在此线程最后一个注释可以给你一个起点http://code.google.com/p/fullcalendar/issues/detail ?id = 105 – 2012-04-24 21:11:42

+0

如果你以某种方式实现这一点。您将失去拖动功能。你能接受吗? – 2012-04-25 21:50:37

+0

是的,我只需要复制,而不是移动事件... – kender 2012-04-26 07:47:58

回答

1

试试这个:

eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view) { 
    // Create an event object and copy at least the start date and the title from event 
    var eventClone = { 
     title:event.title, 
     start: event.start, 
     end: event.end 
    }; 

    // Render new event with new event object 
    $('#calendar').fullCalendar('renderEvent', eventClone); 

    // Revert the changes in parent event. To move it back to original position 
    revertFunc(); 
} 

这只是想法。我没有测试过这个代码。请让我知道它是如何工作的。 谢谢

+0

您可能必须使用[clone方法](http://stackoverflow.com/questions/122102/what-is-the-most-efficient克隆一个JavaScript对象)来创建开始和结束日期的深层副本。但不要克隆整个事件对象。因为它包含可能导致问题的_id(由fullCalendar分配给每个事件的ID)。 – 2012-04-26 13:51:39

5

下面是我的解决方案,允许用户按住shift键复制事件。 请注意,这实际上是在移动原始事件并将副本留在原始位置。

我开始与this reference,并创建了以下内容:

//Before the fullCalendar object 

    var copyKey = false; 
    $(document).keydown(function (e) { 
     copyKey = e.shiftKey; 
    }).keyup(function() { 
     copyKey = false; 
    }); 

//then inside the fullCalendar object 

    eventDragStart: function (event, jsEvent, ui, view) { 
     if (!copyKey) return; 
     var eClone = { 
      title: event.title, 
      start: event.start, 
      end: event.end 
     }; 
     $('#calendar').fullCalendar('renderEvent', eClone); 
    }, 
+0

会很高兴看到这一小提琴 – HPWD 2018-01-30 02:13:07