如何动态地将事件源对象更新为完整日历中的特定事件源

时间:2017-11-23 15:07:48

标签: angularjs fullcalendar

您好我使用以下代码加载了一个日历。

dataFactory.httpRequest('getCalanderTaskData','GET').then(function(data) {
            $scope.taskCalanderDailyTask = data.dailyTask;
            $scope.taskCalanderDueTask = data.dueTask;
            $scope.fullCalendarEventSources = {
                dailyTask : {
                    events:$scope.taskCalanderDailyTask,
                    textColor : '#000',
                    backgroundColor: '#FFD000',
                },
                dueTask : {
                    events:$scope.taskCalanderDueTask,
                    textColor : '#fff',
                    backgroundColor: '#da1445',  
                }

            };
            $('#fullcalendar').fullCalendar({

                eventClick: function(calEvent, jsEvent, view) {
                },
                eventMouseover: function(calEvent, jsEvent, view) {
                    var tooltip = '<div class="tooltipevent" style="color:#fff;width:100px;height:50px;background:#125688;position:absolute;z-index:10001;">' + calEvent.title + '</div>';
                    var $tooltip = $(tooltip).appendTo('body');
                    $(this).mouseover(function(e) {
                        $(this).css('z-index', 10000);
                        $tooltip.fadeIn('500');
                        $tooltip.fadeTo('10', 1.9);
                    }).mousemove(function(e) {
                        $tooltip.css('top', e.pageY + 10);
                        $tooltip.css('left', e.pageX + 20);
                    });
                },
                eventMouseout: function(calEvent, jsEvent) {
                    $(this).css('z-index', 8);
                    $('.tooltipevent').remove();
                },
                eventLimit: 3,
                eventSources: [$scope.fullCalendarEventSources.dailyTask, $scope.fullCalendarEventSources.dueTask],

            });

      });

上面的代码加载第一次日历时,任何新的任务将被添加我想要刷新日历事件源而不重新加载页面。

下面是saveTask的代码。我已经为动态事件源编写了代码,它也删除了源代码和添加的源代码,但它没有更新新添加的任务。

$scope.saveTask = function(){
        $scope.form.taskLeadId =  $scope.leadId;
        $scope.form.taskId =  $scope.editTaskId;
        if($scope.form.taskLeadId != "undefined" && $scope.form.taskLeadId != "")
        {
            dataFactory.httpRequest('taskCreate','POST',{},$scope.form).then(function(data) {
                if(data.status == 1)
                {
                    alertify.notify(data.message, 'success', 5, function(){});
                    $scope.addTask.$setPristine();
                    $scope.addTask.$setUntouched();
                    $scope.form = {};
                    $(".modal").modal("hide");
                    getDailyTaskData();
                    getCalanderTaskData();
                    console.log("updateed=="+$scope.taskCalanderDailyTask);
                    $scope.fullCalendarEventSources = {
                        dailyTask : {
                            events:$scope.taskCalanderDailyTask,
                            textColor : '#000',
                            backgroundColor: '#FFD000',
                        },
                        dueTask : {
                            events:$scope.taskCalanderDueTask,
                            textColor : '#fff',
                            backgroundColor: '#da1445',  
                        }

                    };
                $timeout(function () {
                    $('#fullcalendar').fullCalendar('removeEventSource',$scope.fullCalendarEventSources.dailyTask);
                    console.log("updateed=="+$scope.taskCalanderDailyTask);
                    $('#fullcalendar').fullCalendar('addEventSource',$scope.fullCalendarEventSources.dailyTask);
                    $('#fullcalendar').fullCalendar('refetchEventSources',$scope.fullCalendarEventSources.dailyTask);
                    $('#fullcalendar').fullCalendar('rerenderEvents');
                    $('#fullcalendar').fullCalendar('refetchEvents');
                    $('#fullcalendar').fullCalendar('refresh');
                    $('#fullcalendar').fullCalendar('updateEvents',$scope.fullCalendarEventSources.dailyTask);
                        $('#fullcalendar').fullCalendar('rerenderEvents');
                    $('#fullcalendar').fullCalendar('refetchEvents');
                    $('#fullcalendar').fullCalendar('refresh');
                    console.log("after update==");
                });



                    //alertify.alert('Task', 'Congratulations your task is created successfully!');

                }
                else
                {
                    if($scope.editTask = "edit")
                    {
                        alertify.alert('Task Update','Nothing is updated');
                    }
                    else
                    {
                        alertify.alert('Error', data.message,function(){ alertify.error(data.message)});
                        $(".modal").modal("hide");
                    }
                }
            });
        }
        else
        {
            alertify.alert('Error', 'There must be something went wrong please try again later');
            $(".modal").modal("hide");
        }
    }

任何人请帮忙。

0 个答案:

没有答案