思路:使用冒泡的方法,从上往下遍历
代码:
function transformOrgs (arr) {
return arr.map((e, i) => {
if (e.mktCitiesList) {
e.children = e.mktCitiesList
e.identifier = e.provinceid
e.name = e.province
} else if (e.mkt_areasList) {
e.children = e.mkt_areasList
e.identifier = e.cityid
e.name = e.city
} else if (e.sys_gasstationList) {
e.children = e.sys_gasstationList
e.identifier = e.areaid
e.name = e.area
} else {
e.identifier = e.STATION_CODE
e.name = e.STATION_NAME
}
if (e.children) {
transformOrgs(e.children)
}
return e
})
}
请求到的数据如下图: