2017-10-13 60 views
0

我在管上創建對象的簡單循環:環路上的物體​​的角4和lodash打字稿錯誤

transform(value: any, args?: any): any { 
     let room; 
     _.forEach(this.rooms,function (el,index) { 
      console.log(el); 
      if(el.id == value){ 
      room == el; 
      } 
     }); 
     return room; 
    } 

我可以在控制檯上,我的目標「厄爾尼諾」有內部物業編號看,但我不能檢查。我使用lodash庫來循環,但我得到錯誤:「屬性'id'類型'{}'上不存在」。

如何避免這種情況我必須創建雙循環訪問一個屬性?

回答

0

嘗試使用箭頭功能,看看

_.forEach(this.rooms,(el: any) =>{ 
     console.log(el); 
     if(el.id == value){ 
      room == el; 
     } 
    });