2017-10-13 59 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; 
     } 
    });