我在angular中使用fullcalendar,如果他们通过if检查,我想在日历中呈现我的数据。
以下是三个略有不同的相同例子:
没有if句子的forloop:
for (var i = 0; i < response.length; i++) {
$scope.open_Courses.push({
id: $scope.temp[i].id,
title: $scope.temp[i].name,
start: new Date($scope.temp[i].date).getTime(),
editable: true,
className: 'b-l b-2x b-info',
location: $scope.temp[i].location,
info: $scope.temp[i].description
});
//render event to calendar
$('.calendar').fullCalendar('renderEvent', $scope.open_Courses[i], true);
}
带有if语句但只在数组中呈现索引0的循环:
for (var i = 0; i < response.length; i++) {
if (new Date($scope.temp[i].date).getTime() >= $scope.time) {
$scope.open_Courses.push({
id: $scope.temp[i].id,
title: $scope.temp[i].name,
start: new Date($scope.temp[i].date).getTime(),
editable: true,
className: 'b-l b-2x b-info',
location: $scope.temp[i].location,
info: $scope.temp[i].description
});
//render event to calendar
$('.calendar').fullCalendar('renderEvent', $scope.open_Courses[0], true);
}
}
最后一个在数组中使用i-index:
for (var i = 0; i < response.length; i++) {
if (new Date($scope.temp[i].date).getTime() >= $scope.time) {
$scope.open_Courses.push({
id: $scope.temp[i].id,
title: $scope.temp[i].name,
start: new Date($scope.temp[i].date).getTime(),
editable: true,
className: 'b-l b-2x b-info',
location: $scope.temp[i].location,
info: $scope.temp[i].description
});
//render event to calendar
$('.calendar').fullCalendar('renderEvent', $scope.open_Courses[i], true);
}
}
第一个和第二个工作正常,但最后一个,这是我想要做的,但不是。它变得未定义并且出错:
TypeError:无法读取未定义
的属性'_id'对我来说,第二个和第三个例子基本相同,所以这怎么可能发生?