returns the corresponding value by comparing the names of provinces, cities and regions. It doesn"t seem feasible to use recursion or filter. Is there a short and elegant way to write it
getChinaArea(province,city,area){
let result = []
//
if(!province){
this.localData.forEach((items)=>{
if(items.label === city){
result.push(items.value)
if(items.children){
items.children.forEach((item)=>{
if(item.label === area){
result.push(item.value)
}
})
}
}
})
}else{
//
this.localData.forEach((items)=>{
if(items.label === province){
result.push(items.value)
if(items.children){
items.children.forEach((item)=>{
if(item.label === city){
result.push(item.value)
if(item.children){
item.children.forEach((i)=>{
if(i.label === area){
result.push(i.value)
}
})
}
}
})
}
}
})
}
return result
}
the data structure is like this
{
value: 3,
label: "",
children: [{
value: 3,
label: "",
children: [{
value: 37,
label: ""
},
{
value: 38,
label: ""
},
{
value: 39,
label: ""
},
{
value: 40,
label: ""
},
{
value: 41,
label: ""
},
{
value: 42,
label: ""
},
{
value: 43,
label: ""
},
{
value: 44,
label: ""
},
{
value: 45,
label: ""
},
{
value: 46,
label: ""
},
{
value: 47,
label: ""
},
{
value: 48,
label: ""
},
{
value: 49,
label: ""
},
{
value: 50,
label: ""
},
{
value: 51,
label: ""
},
{
value: 52,
label: ""
},
{
value: 53,
label: ""
},
{
value: 54,
label: ""
},
{
value: 55,
label: ""
},
{
value: 56,
label: ""
},
{
value: 57,
label: ""
},
{
value: 58,
label: ""
},
{
value: 59,
label: ""
}
]
},