[{
"value": 130000,
"label": "河北省",
"children": [
{
"value": 130100,
"label": "石家庄市",
"children": [
{
"value": 130102,
"label": "长安区",
"children": null
},
{
"value": 130104,
"label": "桥西区",
"children": null
},
{
"value": 130105,
"label": "新华区",
"children": null
},
{
"value": 130107,
"label": "井陉矿区",
"children": null
},
{
"value": 130108,
"label": "裕华区",
"children": null
},
{
"value": 130109,
"label": "藁城区",
"children": null
},
{
"value": 130110,
"label": "鹿泉区",
"children": null
},
{
"value": 130111,
"label": "栾城区",
"children": null
},
{
"value": 130121,
"label": "井陉县",
"children": null
},
{
"value": 130123,
"label": "正定县",
"children": null
},
{
"value": 130125,
"label": "行唐县",
"children": null
},
{
"value": 130126,
"label": "灵寿县",
"children": null
},
{
"value": 130127,
"label": "高邑县",
"children": null
},
{
"value": 130128,
"label": "深泽县",
"children": null
},
{
"value": 130129,
"label": "赞皇县",
"children": null
},
{
"value": 130130,
"label": "无极县",
"children": null
},
{
"value": 130131,
"label": "平山县",
"children": null
},
{
"value": 130132,
"label": "元氏县",
"children": null
},
{
"value": 130133,
"label": "赵县",
"children": null
},
{
"value": 130181,
"label": "辛集市",
"children": null
},
{
"value": 130183,
"label": "晋州市",
"children": null
},
{
"value": 130184,
"label": "新乐市",
"children": null
}
]
}
]
} ]根据[130000,130100,130102]查找出河北省石家庄市长安区
function findLocationByValue(data, values) {
if (!Array.isArray(values) || values.length === 0) {
return null;
}
const targetValue = values[0];
const targetItem = data.find(item => item.value === targetValue);
if (!targetItem) {
return null;
}
if (values.length === 1) {
return targetItem.label;
}
const remainingValues = values.slice(1);
const childLocation = findLocationByValue(targetItem.children, remainingValues);
if (childLocation) {
return `${targetItem.label}${childLocation}`;
}
return null;
}
const valuesToFind = [130000, 130100, 130102];
const result = findLocationByValue(data, valuesToFind);
console.log(result);