【发布时间】:2022-11-23 02:53:45
【问题描述】:
我有一个名为dataLookup 的对象,其内容为https://pastebin.com/MG4xB8ht。
这是其中一项的样子:
{
"key": "Andaman & Nicobar",
"value": {
"state": "Andaman & Nicobar",
"fcra_registered": 8,
"total": 140
}
},
我想访问每个 key 的 total 值并将其分配给另一个组件中的道具。
我有这个:
z={(d) => dataLookup.get(d["state"])["total"]}
这给了我一个错误:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'total')
我做错了什么,我该如何解决?
更新:我添加了整个问题的工作 REPL。您可以在控制台中看到错误。 It is here,错误出现在第62行。
【问题讨论】:
-
错误发生时
d["state"]和dataLookup.get(d["state"])是什么? -
@mykaf 我如何找到它?
-
您能否将其更新为可运行的minimal reproducible example,它可以演示问题并指示您期望的结果?
-
你知道如何使用
console.log()吗? -
您如何将数据添加到地图?
标签: javascript dictionary