Fullcalendar-scheduler updateEvent是具有不同ID的音符更新事件

时间:2018-07-30 05:31:25

标签: jquery javascript-events fullcalendar fullcalendar-scheduler

我试图一次更新一个事件,但是updateEvent更新所有事件,所有事件都有单独的Id和_Id,第一次它对于一个事件运行完美,但是第一次之后,当我们编辑其他事件时,每个它会更新与当前编辑事件类似的先前编辑值。使用回调函数eventClick获取原始事件。

$(function () {
        $('#event_time_edit').daterangepicker({
            timePicker: true,
            timePickerIncrement: 30,
            locale: {
                format: 'DD/MM/YYYY h:mm A'
            }
        });

        if (typeof ($.fn.fullCalendar) === 'undefined') {
            return;
        }

        var calendar = $('#rehabCalender').fullCalendar({
            schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
            selectable: true,
            header: {
                left: 'today prev,next',
                center: 'title',
                right: 'timelineDay,timelineWeek,timelineMonth,listMonth'


            },
            defaultView: 'timelineMonth',
            resourceGroupField: 'building',
            resourceLabelText: 'Categories',
            eventClick: function (calEvent, jsEvent, view) {
                var event = calEvent;
                
                $('#CalenderModalEdit').modal("show");

                $('#title2').val(event.title);

                var end = moment(event.end._i).format("DD/MM/YYYY h:mm A");
                var start = moment(event.start._i).format("DD/MM/YYYY h:mm A");
                var dateAndTime = start + " - " + end;
                $('#event_time_edit').val(dateAndTime);
                $("#event_time_edit").data('daterangepicker').setStartDate(start);
                $("#event_time_edit").data('daterangepicker').setEndDate(end);
                
               
                $(".antosubmit2").on("click", function (e) {
                    event.start = moment($('#event_time_edit').data('daterangepicker').startDate._d).format("YYYY-MM-DD HH:mm:ss");
                    event.end = moment($('#event_time_edit').data('daterangepicker').endDate._d).format("YYYY-MM-DD HH:mm:ss");
                    event.title = $("#title2").val();
                    event.desc = $("#descr2").val();
                    
                    calendar.fullCalendar("updateEvent", event);
                    $('#CalenderModalEdit').modal('hide')
                });
                calendar.fullCalendar('unselect');

            },
            editable: true,
            resources: [{"id":"7","title":"TRAINER","children":[{"id":"8","parentId":"7","title":"Static truck exercises","children":[{"id":"9","parentId":"8","title":"Crook Lying"},{"id":"10","parentId":"8","title":"4 pt"},{"id":"11","parentId":"8","title":"Bridging"},{"id":"12","parentId":"8","title":"Plank"},{"id":"13","parentId":"8","title":"Side Support (Side Plank)"}]},{"id":"14","parentId":"7","title":"Dynamic Trunk Control\/Mobility","children":[{"id":"15","parentId":"14","title":"Mat Exercises"},{"id":"16","parentId":"14","title":"Physio Ball"},{"id":"17","parentId":"14","title":"Standing"}]},{"id":"18","parentId":"7","title":"Aerobic","children":[{"id":"19","parentId":"18","title":"Cycling (Easy Spining)"},{"id":"20","parentId":"18","title":"Cross Trainer \/ Stepper"},{"id":"21","parentId":"18","title":"Supine \/ Sitting Weights"}]},{"id":"22","parentId":"7","title":"Water Based","children":[{"id":"23","parentId":"22","title":"Hydrotherapy"},{"id":"24","parentId":"22","title":"Deep Water Running"},{"id":"25","parentId":"22","title":"Shallow Water Jogging"},{"id":"26","parentId":"22","title":"Shallow Water Running"}]},{"id":"27","parentId":"7","title":"FWB weight lifting","children":[{"id":"28","parentId":"27","title":"Squats, Calf Raises, Lunges etc"},{"id":"29","parentId":"27","title":"Upper Limb"}]}]},{"id":"30","title":"SPORTS SPECIFIC","children":[{"id":"31","parentId":"30","title":"Running","children":[{"id":"35","parentId":"31","title":"Jogging"},{"id":"36","parentId":"31","title":"Running \/ Sprinting"},{"id":"37","parentId":"31","title":"Cutting \/ Turning"}]},{"id":"32","parentId":"30","title":"Batting","children":[{"id":"38","parentId":"32","title":"Shadow Batting"},{"id":"39","parentId":"32","title":"Batting Practice (nets)"},{"id":"40","parentId":"32","title":"Batting Match"}]},{"id":"33","parentId":"30","title":"Fielding Practice","children":[{"id":"41","parentId":"33","title":"Catching"},{"id":"42","parentId":"33","title":"Throwing"},{"id":"43","parentId":"33","title":"Running"}]},{"id":"34","parentId":"30","title":"Bowling","children":[{"id":"44","parentId":"34","title":"Drills"},{"id":"45","parentId":"34","title":"Short-run"},{"id":"46","parentId":"34","title":"Full-run"},{"id":"47","parentId":"34","title":"Bowling Match"}]}]},{"id":"1","title":"PHYSIO","children":[{"id":"4","parentId":"1","title":"Lx \/ tx Manual Therapy"},{"id":"6","parentId":"1","title":"LIPUS (Low intensity pulsed US -exogen)"}]},{"id":"3","title":"PHYSICAL Conditioning"}]
,
            events: [{"id":"1","resourceId":"8","desc":"crisp desc","title":"crisp","start":"2018-07-10 00:00:00","end":"2018-07-27 00:00:00"},{"id":"2","resourceId":"9","desc":"Crook Lying desc","title":"Crook Lying","start":"2018-07-03 00:00:00","end":"2018-08-17 23:00:00"}],
            eventRender: function (eventObj, $el) {
                $el.popover({
                    title: eventObj.title,
                    content: eventObj.desc,
                    trigger: 'hover',
                    placement: 'top',
                    container: 'body'
                });
            },
            dayClick: function (date, jsEvent, view, resource) {

            },
            select: function (startDate, endDate, jsEvent, view, resource) {

            },
        });
    });

1 个答案:

答案 0 :(得分:1)

好吧,我得到的答案是我动态绑定了单击事件,它会一次又一次地启动克隆,所以我只是取消了绑定第一次单击事件并重新生成下一个代码。

 $(".antosubmit2").unbind('click').on("click",function (e) {
     code goes here
 });