打字稿:比较映射到对象列表

时间:2019-02-16 20:06:41

标签: javascript typescript dictionary angular6

我正在尝试遍历对象列表(具有ID作为属性),并且该对象的ID与Map中条目的键相匹配,我想更新该对象的另一个属性与相应地图的值。

示例地图值:

0: {12095088 => 456}
1: {12095084 => 0}
2: {12095106 => 0}

对象值示例:

0: {customfppg: 76.93, player: "Bill", playerid: 12095088, …}
1: {customfppg: 86.38, player: "Jim", playerid: 12095084, …}
2: {customfppg: 90.54, player: "John", playerid: 12095106, …}

如果player.playerid等于地图的键,则获取该地图条目的值并更新player.customfppg的值。这是我的代码:

let importedProjectionList = this.excelService.importCustomProjectionTemplate(file);

this.playerSource.data.forEach(player => {
  if(importedProjectionList.has(player.playerid)) {
      player.customfppg = importedProjectionList.get(player.playerid);
    }        
  });

即使我肯定会有很多比赛,我似乎也永远无法触发if语句。我不知道为什么这永远不会匹配。我已经仔细检查过相同类型(数字)的地图键和玩家ID值-仍然没有乐趣。

0 个答案:

没有答案
相关问题