"showModule": [{
"action_id": "21",
"action_name": "",
"action_type": "1",
"order": "1",
"pid": "0"
}, {
"action_id": "20",
"action_name": "",
"action_type": "1",
"order": "2",
"pid": "0",
"son": [{
"action_id": "22",
"action_name": "",
"action_type": "2",
"order": "1",
"pid": "20",
"son": [{
"action_id": "23",
"action_name": "",
"action_type": "3",
"order": "1",
"pid": "22"
}, {
"action_id": "24",
"action_name": "",
"action_type": "3",
"order": "2",
"pid": "22"
}, {
"action_id": "25",
"action_name": "",
"action_type": "3",
"order": "4",
"pid": "22"
}, {
"action_id": "31",
"action_name": "",
"action_type": "3",
"order": "4",
"pid": "22"
}]
}, {
"action_id": "26",
"action_name": "",
"action_type": "2",
"order": "2",
"pid": "20",
"son": [{
"action_id": "27",
"action_name": "",
"action_type": "3",
"order": "1",
"pid": "26"
}, {
"action_id": "28",
"action_name": "",
"action_type": "3",
"order": "2",
"pid": "26"
}, {
"action_id": "29",
"action_name": "",
"action_type": "3",
"order": "3",
"pid": "26"
}, {
"action_id": "30",
"action_name": "",
"action_type": "3",
"order": "4",
"pid": "26"
}]
}],
the data structure is like this
I want to deal with the data structure
. How should I write it like this?
showModule:{
label: action_name,
value: action_id,
son:[
{
label: action_name,
value: action_id,
son:{
label: action_name,
value: action_id,
}
},
{
label: action_name,
value: action_id
}
]
}
if you write it like this, you can circulate the first level. If you use map on item.son, you will report an error
. const mapData = data.showModule.map(item => ({
label: item.action_name,
value: item.action_id,
subModule: item.son
}))