fullcalendar drop in add event

时间:2018-03-11 06:10:17

标签: jquery fullcalendar jquery-ui-draggable

我正在改变自己的责任。我在我的项目中使用FullCalendar。我也想使用我在drop中的事件中使用的回调。简而言之,我想将从列表中拖动的事件添加到日历中,如何在drop中执行此操作? 提前致谢

的Javascript;

 $('#m_calendar').fullCalendar({
                drop: function (date, jsEvent, ui, resourceId) {
                    jsEvent.originalEvent.preventDefault();
                    var title = jsEvent.target.dataset.title;
                    var start = jsEvent.target.dataset.start;
                    var end = jsEvent.target.dataset.end;
                    var id = jsEvent.target.dataset.id;

                    var newEvent = new Object();
                    newEvent = {
                        title: title,
                        id: id,
                        start: start,
                        end: end,
                        objectID: 0
                    };
                    eventsAdded.push(newEvent);   

                },
                events: function (start, end, timezone, callback) {
                    $.ajax({
                        url: '/Schedule/GetCalendarEvents',
                        dataType: 'xml',
                        data: {
                            start: start.unix(),
                            end: end.unix()
                        },
                        success: function (doc) {
                            var events = [];
                            $(doc).find('event').each(function () {
                                events.push({
                                    id: $(this).attr('id'),
                                    title: $(this).attr('title'),
                                    start: $(this).attr('start'),
                                    end: $(this).attr('end')
                                });
                            });
                            callback(events);
                        },
                        error: function () {
                            alert('there was an error while fetching events!');
                        },
                    });
                },
            });

1 个答案:

答案 0 :(得分:0)

你有两个选择,

1)如果您将事件数据包含在拖动到日历中的draggable属性中,则当您删除该事件时,该事件将自动添加到日历中。有关如何指定数据的详细信息,请参阅https://fullcalendar.io/docs/eventReceive。另请参阅https://fullcalendar.io/docs/external-dragging-demo处的外部拖动演示以获取工作示例 - 您可以查看链接的CodePen中的源代码,了解它是如何完成的。

2)要修改当前代码,只需调用

即可
$("#m_calendar").fullCalendar("renderEvent", newEvent, true);

在“drop”回调结束时。

这会将新事件添加到日历显示中。当然,如果您需要将它添加到数据库中,您还需要同时对服务器进行适当的调用。

有关文档,请参阅https://fullcalendar.io/docs/renderEvent

P.S。在您编辑它之前,这曾经是一个完全不同的问题(请参阅问题的编辑历史记录)。将来请不要将问题编辑为新问题......有人可能仍想回答以前的版本。提出一个全新的问题(如果您不再需要,请删除旧问题)。否则,之前的评论或答案(例如我在此处发布的评论,现已删除)将毫无意义。感谢。

相关问题