【发布时间】:2021-11-02 16:34:37
【问题描述】:
我有一个嵌套的 json 对象:
{
"51": {
"wheels": 10,
"id": 1,
"name": "truck"
},
"55": {
"wheels": 4,
"id": 33,
"name": "Car"
},
"88": {
"wheels": 2,
"id": 90,
"name": "Bike"
}
}
我想按 ID 过滤,但只返回轮子,即。
过滤器 ID = 33,这将返回 4。
我曾尝试使用 .filter 函数,但出现错误:filter is not a function 我认为这是因为这不是数组。我试图在这里使用答案进行复制:
How to filter deeply nested json by multiple attributes with vue/javascript
没有成功,因为 json 有一个键 (51, 55, 88) 所以我很难过。
提前感谢您的帮助。
【问题讨论】: