【问题标题】:Unable to display custom events on angular full calendar无法在角度完整日历上显示自定义事件
【发布时间】:2015-10-07 10:33:55
【问题描述】:

我推送从服务器加载的事件,但它们没有显示。它们的格式与所有示例中的格式相同,如果我在页面中打印,它们会以正确的格式显示……但从未显示在日历中……

这是我的代码

dashboardCtrl.controller('CalendarioCtrl', ['$scope', '$log', '$compile', 'uiCalendarConfig', 'SedutaGiuntaSrvc', 'ProgressivoSrvc', function ($scope, $log, $compile, uiCalendarConfig, SedutaGiuntaSrvc, ProgressivoSrvc) {
$scope.events = [];

/* lista delle sedute */
var loadSedutePerCalendario = function () {
    SedutaGiuntaSrvc.getSeduteCalendario().then(function (response) {
        if ('item' in response.data.response.result.items) {
            var sedute = convertToArray(response.data.response.result.items.item);
            angular.forEach(sedute, function (s, index) {
                if (index < sedute.length) {
                    var date = new Date(s.data);
                    var d = date.getDate();
                    var m = date.getMonth();
                    var y = date.getFullYear();
                   $scope.events.push({id: s.id, title: s.progressivo + '_' + y, start: new Date(y, m, d+1)}); 
                }
            });
        }
    });
};

loadSedutePerCalendario();

$scope.eventSources = [$scope.events];

        /* alert on eventClick */
        $scope.alertOnEventClick = function (date, jsEvent, view) {
            $scope.alertMessage = (date.title + ' was clicked ');
        };
        /* alert on Drop */
        $scope.alertOnDrop = function (event, delta, revertFunc, jsEvent, ui, view) {
            $scope.alertMessage = ('Event Droped to make dayDelta ' + delta);
        };
        /* alert on Resize */
        $scope.alertOnResize = function (event, delta, revertFunc, jsEvent, ui, view) {
            $scope.alertMessage = ('Event Resized to make dayDelta ' + delta);
        };
        /* add and removes an event source of choice */
        $scope.addRemoveEventSource = function (sources, source) {
            var canAdd = 0;
            angular.forEach(sources, function (value, key) {
                if (sources[key] === source) {
                    sources.splice(key, 1);
                    canAdd = 1;
                }
            });
            if (canAdd === 0) {
                sources.push(source);
            }
        };

        /* Change View */
        $scope.changeView = function (view, calendar) {
            uiCalendarConfig.calendars[calendar].fullCalendar('changeView', view);
        };
        /* Change View */
        $scope.renderCalender = function (calendar) {
            if (uiCalendarConfig.calendars[calendar]) {
                uiCalendarConfig.calendars[calendar].fullCalendar('render');
            }
        };
        /* Render Tooltip */
        $scope.eventRender = function (event, element, view) {
            element.attr({'tooltip': event.title,
                'tooltip-append-to-body': true});
            $compile(element)($scope);
        };
        /* config object */
        $scope.uiConfig = {
            calendar: {
                height: 450,
                editable: true,
                header: {
                    left: 'title',
                    center: '',
                    right: 'today prevYear prev,next nextYear'
                },
                eventClick: $scope.alertOnEventClick,
                eventDrop: $scope.alertOnDrop,
                eventResize: $scope.alertOnResize,
                eventRender: $scope.eventRender
            }
        };
    }]);

问题出在哪里?

这就是我在页面中打印的 eventSources 内容

[{"id":1,"title":"1/2014","start":"2014-10-06T22:00:00.000Z","_id":1}]

我查看了Angularjs Full Calendar doesn't display events 的帖子,但它并没有解决我的问题

【问题讨论】:

    标签: javascript angularjs calendar fullcalendar


    【解决方案1】:
    $scope.eventSources = [fetchEvents];
              function fetchEvents(start, end, timezone, callback) {
                        //ur data will be ppushed to scope events here
                          callback($scope.events);
                          });
             }
    

    【讨论】:

    • 仅由代码组成的答案不是答案。请详细说明。
    【解决方案2】:

    eventSources 必须是数组数组,看起来是这样的:

    $scope.events = [{"id":1,"title":"1/2014","start":"2014-10-06T22:00:00.000Z","_id":1}];
    $scope.eventSources = [$scope.events]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-15
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多