完整的日历事件出现两次

时间:2018-11-22 08:48:11

标签: javascript jquery ajax fullcalendar

创建事件后,样式仍然保留。但是有时事件似乎是重复的。随附了jquery代码和屏幕截图,以便于更好地理解。

enter image description here

这是从后端加载后事件的外观

这是我的jquery函数

select: function (start, end) {
                        var title = "Available";
                        var eventData;
                        if (title) {
                            eventData = {
                                title: title,
                                start: start,
                                end: end
                            };
                            $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true

                            createEvent(eventData);

                            window.setTimeout(function () {
                                location.reload()
                            }, 300);

                            $.notifyBar({
                                cssClass: "WARNING",
                                html: "Created Successfully."
                            });
                        }
                        $('#calendar').fullCalendar('unselect');

                    },

    eventSources: [{
                    events: function (start, end, timezone, callback) {
                        var employeeId = $("#employee-Id").val();
                        $.ajax({
                            url: '../' + employeeId + '/events',
                            dataType: 'json',
                            success: function (response) {
                                var events = $.parseJSON(response.data);
                                callback(events);
                            }
                        });
                    }
                }],
                eventRender: function (event, element) {
                    //delete event on double click..Tanvir
                    element.unbind("dblclick").one().bind('dblclick', function (e) {

                        $("#startTime").html(moment(event.start).format(' DD/MM/YYYY, HH:mm'));
                        $("#endTime").html(moment(event.end).format('DD/MM/YYYY, HH:mm'));

                        $("#eventContent").dialog({modal: true, title: event.title, width: 100});

                        $('.delete-event').unbind("click").click(function (e) {
                            e.preventDefault();
                            $('#calendar').fullCalendar('removeEvents', event._id);
                            deleteEvent(event.id);
                            $("#eventContent").hide();

                        });

                        $('.discard-delete').bind('click', function () {
                            $("#eventContent").hide();
                        });
                    });

    function createEvent(eventData) {
                $(document).ready(function () {
                    $(function () {
                        $.ajax(
                            {
                                beforeSend: function (xhr) {
                                    xhr.setRequestHeader("Accept", "application/json");
                                },
                                url: '../availability/create',
                                contentType: "application/json",
                                type: 'GET',
                                traditional: true,
                                data: {
                                  eventsJson:JSON.stringify(eventData),
                                  id: $("#employee-Id").val()
                                },
                                dataType: "json",
                                success: function (response) {
                                },
                                error: function (xhr) {

                                }

                            });
                    });
                });
            }

这就是我所能提供的全部。请随时询问您是否需要更多信息

0 个答案:

没有答案