我遇到了这个错误:
ERROR : DISCIPLINE.EVENTS is NULL
由第二个if
声明提出。
以下是代码:
angular.forEach($scope.form.disciplines, function(discipline) {
if (angular.isUndefined(discipline.events) || discipline.events == null){
angular.forEach(discipline.compets, function(compet) {
var key = compet.eventCode;
if (angular.isUndefined(discipline.events[key]) || discipline.events[key] == null) {
discipline.events[key] = {fhi:{presented : null, box : null, notAccepted : null, withdrawn : null, accepted : null}} }
});
}
});
感谢所有人。
答案 0 :(得分:0)
错误在这里,discipline.events
不是数组,等于null:
discipline.events[key]
在获取数组值之前,请测试事件是否为null或是否为数组。像这样:
if (!discipline.events || angular.isUndefined(discipline.events[key]) || discipline.events[key] == null) {
或者也许:
if (typeof(discipline.events) == "object" || /*...*/) {
答案 1 :(得分:0)
只需将discipline.events
初始化为内部forEach
之前的空数组:
if (...) {
discipline.events = [];
angular.forEach(
...
);
}