2016-12-26 2 views
0

다른 배열을 포함하도록 배열을 수정하려고했습니다. 최대 호출 스택 크기가을 초과했으며 이유를 모릅니다.최대 호출 스택 크기가 배열 내부의 배열을 초과했습니다

app.selected.forEach(function(customer) { 
     app.dateInterval.forEach(function(dateint) { 
      customer[+dateint] = [] 

      app.eventsEmail.forEach(function(event) { 
       var date = event.Data; 
       date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); 
       date = date.setDate(date.getDate() + 1); 

       if (event.IdCustomer == customer.IdCustomer && (+date) == (+dataint)) 
        customer[+dateint].push(event); 


      }); 
     }); 
    }); 

누군가가 그 문제를 해결하는 방법을 알고 있습니까?

+0

당신은 브라우저에서 DevTools로에서 코드를 디버그하는 한? – azad

+0

'.forEach()'호출에서 두 개의 중첩 된'.forEach()'호출의 목적은 무엇입니까? – guest271314

+2

이것이 호출 스택을 오버플로 할 이유가 없습니다. 이 모든 것을 호출 한 곳의 코드를 추가 할 수 있습니까? 재귀 호출? – trincot

답변

0

이 같이 할 수 있습니다 :

var size = app.selected.length; 
for(i=0;i<size;i++){ 
     var customer = app.selected[i]; 
     app.dateInterval.forEach(function(dateint) { 
      customer[+dateint] = [] 

      app.eventsEmail.forEach(function(event) { 
       var date = event.Data; 
       date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); 
       date = date.setDate(date.getDate() + 1); 

       if (event.IdCustomer == customer.IdCustomer && (+date) == (+dataint)) 
        customer[+dateint].push(event); 


      }); 
     }); 
    }); 
} 
+0

이 문제가 어떻게 해결됩니까? 문제는 무엇 이었습니까? –

+0

문제는 아이템을 추가하고 길이가 늘어나고 foreach가 있다는 것입니다 ... 무한 루프 – Araz

관련 문제