1

我对 AngularJS Ui-Calendar有这个问题:

在 fullcalendar 的 select 回调函数中,我通过拖动创建事件,然后将事件添加到我的事件数组中。

创建事件后,我想删除其中的一些,因此我在前面添加了一个按钮,删除,它从 Ui-CalendarCalendar 调用删除函数。功能如下:

function eventRenderFn(event, element, view) {
    element.find(".fc-content").prepend("<button class='closeon btn btn-danger pull-right'>Delete</button>");
    element.find(".closeon").on('click', function() {
        removeEventById(event);
    });
 }

问题是,在我删除一个事件后,即使该事件已从事件数组中删除,该事件仍会显示在日历上。

我尝试在删除函数中添加以下代码来重新呈现事件,但这也没有解决我的问题,因为它只是在第一次删除事件时重新呈现。代码如下:

uiCalendarConfig.calendars.myCalendar.fullCalendar('removeEvents');             
uiCalendarConfig.calendars.myCalendar.fullCalendar('addEventSource', $scope.events);

日历如下所示: 在此处输入图像描述

2天来,我一直在努力寻找解决该问题的方法。

感谢您的时间。

编辑:

我的删除功能是:

function removeEventById(event) {
    angular.forEach($scope.events, function (value, key) {
        if (event._id === value._id) {
            $scope.remove(key);
        }
    });
}

其中$scope.remove(key)是:

$scope.remove = function(index) {
    $scope.events.splice(index, 1);
};
4

0 回答 0