【发布时间】:2021-09-13 17:46:31
【问题描述】:
I'm pulling data from a service that loads into a dropdown and when a value is selected it's being assigned to a variable and an example is below
[{
"id": 482,
"firstName": "Micheal",
"lastName": "Bamford",
"email": "lalacifay@cliptik.net",
"areaCodes": [
{
"id": 60,
"name": "New York",
"status": "ACTIVE",
"createdDate": "2018-10-30 14:09:28"
},
{
"id": 12,
"name": "Florida",
"status": "ACTIVE",
"createdDate": "2018-10-30 14:09:28"
}
],
"createdDate": "2019-01-03 12:29:33"
}]
我想要实现的是只在 areaCodes 这样的 ['New York', 'Florida'] 对象中获取 name 属性
下面是我目前使用的代码,它只让我得到数组中的第一个
const selected = this.listFromAPI.filter(t => t.id === ev.id).map(r=> r.areaCodes[0].name);
【问题讨论】:
-
什么是ev.id?..
-
ev.id 是选择后从下拉列表中抓取的值
-
listFromAPI 是一个数组。它有其他元素吗?您是否想要来自所有元素的所有 areaCodes 的名称,因为您的代码中有带有 id 的过滤器。
标签: javascript angular ecmascript-6