[英]AngularJS + Fullcalendar send error TypeError: Cannot read property '__id' of undefined
我在我的網站上使用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嗎?
我遇到了相同的錯誤,一種解決方法是,初始化事件數組$ scope.events = [],然后發出http請求
使用此參考:
searchObject.technician.__id
沒有定義searchObject.technician
就是問題。
這是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.
我遇到了同樣的問題。 它取決於您定義一切的順序。 為了安全起見,最好先聲明事件源。
HTML:
<div ui-calendar ng-model="eventSources"></div>
控制器:
$scope.events = [
{title: 'Long Event',start: new Date()}
];
$scope.eventSources = [$scope.events];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.