您如何获得对象所有子节点的 JSONPath?
例如:
var data = [{
"key1": {
"children": [{
"key2": "value",
"key3": "value",
"key4": {}
}, {
"key2": "value",
"key3": "value",
"key4": {}
}],
"key5": "value"
}
}, {
"key1": {
"children": {
"key2": "value",
"key3": "value",
"key4": {}
},
"key5": "value"
}
}]
我想将数据结构中所有节点的绝对路径作为数组获取:
[
"data[0]['key1']['children'][0]['key2']",
"data[0]['key1']['children'][0]['key3']",
"data[0]['key1']['children'][0]['key4']",
......,
"data[0]['key1']['children'][1]['key2']",
.......,
"data[1]['key1']['children']['key2']",
..........
]
有没有办法在 JS 中完成这项工作?