【问题标题】:AngularJS + Fullcalendar send error TypeError: Cannot read property '__id' of undefinedAngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'
【发布时间】:2014-06-12 09:58:12
【问题描述】:

我在我的网站中使用 angular-ui-calendar。 在控制器中,我写了这个:

    define(['underscore'], function (_) {
    "use strict";

    var SearchController = function ($scope, $location, OrdersService, UsersService) {

        /* config object */
        $scope.uiConfig = {
            calendar: {
                height: 450,
                editable: true,
                firstDay: 0,
                monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
                monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
                dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'],
                dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
                header: {
                    left: '',
                    center: 'title',
                    right: ''
                }
            }
        };
        $scope.eventSources = [$scope.events];

        var getTecnicians = function () {
            UsersService.getTechs().then(function (techs) {
                $scope.technicians = techs;
            });
        };

        var search = function () {
            var searchObject = $scope.$$childHead.searchForm;
            UsersService.getCurrentStatus(searchObject.technician._id, searchObject.selectedStartDate).then(function (result) {
                $scope.states = result[0].states;
                for (var i = 0; i < $scope.states.length; i++) {
                    var event = {};
                    if (i === $scope.states.length - 1) {
                        event = {
                            title: $scope.states[i].status,
                            start: $scope.states[i].date,
                            allday: true
                        };
                    } else {
                        event = {
                            title: $scope.states[i].status,
                            start: $scope.states[i].date,
                            end: $scope.states[i + 1].date
                        };
                    }
                    $scope.events.push(event)
                }
                if (result) {
                    $scope.haveData = true;
                }
            });
        };

        var init = function () {
            $scope.search = search;
            $scope.getTecnicians = getTecnicians();
            $scope.haveData = false;
            $scope.events = [];
        };
        init();
    };

    SearchController.$inject = ["$scope", "$location", "OrdersService", "UsersService"];

    return SearchController;
});

当我点击一个按钮时,我会发出一个获取请求并从服务器获取数据,处理它并生成事件对象并放入我的范围内。

当我完成它时,日历会显示这个错误:

ypeError: Cannot read property '__id' of undefined
    at sourcesFingerprint (http://localhost:8000/bower_components/angular-ui-calendar/src/calendar.js:48:24)
    at Object.changeWatcher.getTokens (http://localhost:8000/bower_components/angular-ui-calendar/src/calendar.js:88:21)
    at Scope.$get.Scope.$digest (http://localhost:8000/bower_components/angular/angular.js:12243:40)
    at Scope.$get.Scope.$apply (http://localhost:8000/bower_components/angular/angular.js:12516:24)
    at done (http://localhost:8000/bower_components/angular/angular.js:8204:45)
    at completeRequest (http://localhost:8000/bower_components/angular/angular.js:8412:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/bower_components/angular/angular.js:8351:11) 

需要我在事件上加上 _id 吗?

【问题讨论】:

标签: javascript jquery angularjs angular-ui


【解决方案1】:

我遇到了同样的错误,修复它的一种方法是初始化事件数组 $scope.events=[] 然后发出http请求

【讨论】:

    【解决方案2】:

    使用此参考:

    searchObject.technician.__id
    

    没有定义 searchObject.technician 是问题所在。

    【讨论】:

      【解决方案3】:

      这是来自 ui-calendar(here) 的错误。是否为 ui-calendar 添加了 ng-model 属性?

      <div ui-calendar ng-model="eventSources"></div>
      

      另外,init() 之后,似乎$scope.events 是一个空数组。所以我觉得你可以直接通过。

      $scope.eventSources = $scope.events; // this is an array.
      

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题。它归结为您定义所有内容的顺序。为了安全起见,最好最后声明事件源。

        HTML:

        <div ui-calendar ng-model="eventSources"></div>
        

        控制器:

        $scope.events = [
            {title: 'Long Event',start: new Date()}
        ];
        $scope.eventSources = [$scope.events];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-03-03
          • 2016-05-06
          • 1970-01-01
          • 2023-03-09
          • 2021-07-23
          • 1970-01-01
          • 2020-06-17
          • 2021-11-02
          相关资源
          最近更新 更多