there are many service stations under the city that need the data of linkage effect
all the servers are returned to me. My code is as follows, how to optimize
export const dealDistribution = (data) => {
const treeData = []
data.forEach(item => {
const isExit = treeData.find(treeItem => treeItem.cityCode === item.cityCode)
if (!isExit) {
treeData.push({
cityCode: item.cityCode,
cityName: item.cityName,
pickhouseList: []
})
}
})
treeData.map(treeItem => {
data.map(dataItem => {
if (treeItem.cityCode === dataItem.cityCode) {
treeItem.pickhouseList.push({
pickhouseId: dataItem.id,
pickhouseName: dataItem.name
})
}
})
})
return treeData
}