多维数组转一维
let list = [
{
"id":31,
"type":3,
"name":"颜色",
"sysName":"defaultSysName",
"valueType":1,
"list":["红色" ,"黄色" ,"绿色"]
},
{
"id":33,
"type":3,
"name":"尺寸",
"sysName":"defaultSysName",
"valueType":1,
"list":["X" ,"XX" ,"XXL"]
},
{
"id":40,
"type":3,
"name":"大小",
"sysName":"defaultSysName",
"valueType":1,
"list":["1CM" ,"2CM" ,"3CM"]
}
]
list = list.map((itemList) => {
itemList["list"] = itemList["list"].map((item) => {
item = {fieldValue: `${itemList.id}=${item}` ,name:`${itemList.name}:${item}`}
return item
})
return itemList
})
let firstList = list.shift()["list"]
let options = []
if (firstList.length > 0) {
let listItem = list.shift()["list"]
while (listItem) {
firstList.forEach((firstItem) => {
listItem.forEach((item) => {
let option = firstItem.fieldValue
option = `${option}&${item.fieldValue}`
let name= firstItem.name
name= `${name} ${item.name}`
options.push({fieldValue: option ,name:name })
})
})
firstList = options
options = []
if(list.length > 0){
listItem = list.shift()["list"]
}else {
listItem = undefined
}
}
console.log(firstList)
}