2014-07-17 59 views
0

空我遇到這個錯誤:錯誤:XXX是angularJS

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

嘗試將其刪除angular.isUndefined(discipline.events)我認爲它來自這裏 – ThomasP1988

回答

0

forEach之前只是初始化discipline.events爲一個空數組:

if (...) { 
    discipline.events = []; 
    angular.forEach(
     ... 
    );        
} 
+0

它的工作原理非常好,非常感謝。 –

0

錯誤是在這裏,discipline.events不會是一個數組,等於null:如果

discipline.events[key] 

數組獲取值之前,測試賽是不爲空或爲數組。就像這樣:

if (!discipline.events || angular.isUndefined(discipline.events[key]) || discipline.events[key] == null) { 

或許:

if (typeof(discipline.events) == "object" || /*...*/) {