2016-12-26 71 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

你debuged你的代碼在瀏覽器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

這是如何解決問題的? **是什麼問題? – 2016-12-26 19:16:22

+0

問題是你正在添加項目和長度增加,並有foreach ...無限循環 – Araz

相關問題