數(shù)組格式轉(zhuǎn)換
let data = {
"合同容量": [
"小",
"中等",
"較大",
"大"
],
"月度敏感": [
"敏感",
"不敏感"
],
"負(fù)荷敏感性": [
"穩(wěn)定",
"不穩(wěn)定"
]
}
let selectData = []
let values = []
Object.values(data).map((val, i) => {
let arr1 = []
val.map((item,ind) => {
arr1.push({
name: item,
value: item
})
})
values.push(arr1)
})
Object.keys(data).map((key,index) => {
selectData.push({
value: key,
name: key,
children: values[index]
})
})
結(jié)果
selectData = [
{
"name": "合同容量",
"value": "1",
"children": [
{
"name": "小",
"value": "1"
},
{
"name": "中等",
"value": "2"
},
{
"name": "較大",
"value": "3"
},
{
"name": "大",
"value": "4"
}
]
},
{
"name": "月度敏感",
"value": "2",
"children": [
{
"name": "敏感",
"value": "1"
},
{
"name": "不敏感",
"value": "2"
}
]
},
{
"name": "負(fù)荷敏感性",
"value": "3",
"children": [
{
"name": "穩(wěn)重",
"value": "1"
},
{
"name": "不穩(wěn)重",
"value": "2"
}
]
}
]