【发布时间】:2021-03-09 10:49:21
【问题描述】:
采取如下json结构,如何在下4层的categories节点上进行过滤。
例如,在这个例子中只返回一个包含“cat8”的项目的json对象,我会得到项目A和B?
我正在使用节点并安装了 lodash。
我会在源头正常过滤数据,但我有数据集,我不能这样做。
{
"items": [
{
"fields": {
"title": "Item A",
"section1": {
"fields": {
"title": "Level 2 title",
"section2": {
"fields": {
"title": "Level 3 title",
"section3": {
"fields": {
"title": "Level 4 title",
"categories": [
"cat1",
"cat6",
"cat8"
]
}
}
}
}
}
}
}
},
{
"fields": {
"title": "Item B",
"section1": {
"fields": {
"title": "Level 2 title",
"section2": {
"fields": {
"title": "Level 3 title",
"section3": {
"fields": {
"title": "Level 4 title",
"categories": [
"cat1",
"cat8"
]
}
}
}
}
}
}
}
},
{
"fields": {
"title": "Item C",
"section1": {
"fields": {
"title": "Level 2 title",
"section2": {
"fields": {
"title": "Level 3 title",
"section3": {
"fields": {
"title": "Level 4 title",
"categories": [
"cat1",
"cat3"
]
}
}
}
}
}
}
}
}
]
}
【问题讨论】:
标签: javascript arrays json lodash