How to send only updated events as json to server on fullcalendar?

怎甘沉沦 提交于 2019-12-08 11:56:04

问题


I have a appointment booking usecase where I get the all previously stored appointments when the user clicks. After I add new appointments or change existing ones and click submit, all appointments including the older ones should go to the server, and there by creating duplicates. What I want is to set only those appointments in the a json that were created by events.

$('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        selectable: true,
        selectHelper: true,
        select: function(start,end,date,jsEvent, view) {                    
           var myDate = new Date();
                var daysToAdd = 45;
                var futureBlockDate = new Date();
                futureBlockDate.setDate(myDate.getDate() + daysToAdd);
                 var allDay = !start.hasTime() && !end.hasTime();

                if (date > futureBlockDate || date<myDate) {

                alert("You cannot set appointment on this day!");    
                }
                else
                {

            var title = prompt('Event Title:');
            var eventData;
            if (title) {
                eventData = {
                    title: title,
                    start: start,
                    end: end

                };
                $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
            }
            $('#calendar').fullCalendar('unselect');
            $('#calendar').fullCalendar('renderEvent');


        }

        },
        editable: true,
        eventLimit: true,
        events: '/app/fullCalendar/calendarEvents',//gets previous appointments from db
        eventClick: function(event, element) {

             event.title = "CLICKED!";

          $('#calendar').fullCalendar('updateEvent', event);

         }

    });

For saving the data, I'm getting the events using

   var eventsFromCalendar = $('#calendar').fullCalendar('clientEvents');

Which gives all events including previous events.


回答1:


You can include your own field on event object and filter the events by that field when you collect all events.

eventData = {
                title: title,
                start: start,
                end: end,
                isNew: true //your own field
            };

 var eventsFromCalendar = $('#calendar').fullCalendar('clientEvents', function (event) {
                    return event.isNew == true;
                });


来源:https://stackoverflow.com/questions/33840037/how-to-send-only-updated-events-as-json-to-server-on-fullcalendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!