数组排列数据 sku规格组合
发布时间: 2022-04-07 20:51:05
作者: 王乐园 浏览次数:
490
排列组合函数 可用于SKU组合
let a = [
[
{
"id": 3911,
"val": "白色",
"key": "颜色",
},
{
"id": 3912,
"val": "蓝色",
"key": "颜色",
}
],
[
{
"id": 3924,
"val": "36",
"key": "尺码",
},
{
"id": 3925,
"val": "37",
"key": "尺码",
}
],
[
{
"id": 3924,
"val": "一",
"key": "类型",
},
{
"id": 3925,
"val": "二",
"key": "类型",
}
]
]
const helperFun = function (...chunks) {
let res = []
let helper = function (chunkIndex, prev) {
let chunk = chunks[chunkIndex]
let isLast = chunkIndex === chunks.length - 1
for (let val of chunk) {
let cur = prev.concat(val)
console.log('9999',cur)
if (isLast) {
res.push(cur)
} else {
helper(chunkIndex + 1, cur)
}
}
}
helper(0, [])
return res
}
let data = helperFun(...a);
console.log('---11',data)
//排列组合函数 可用于SKU
上一篇:(转载)追忆过往青春
下一篇:(转载)时光悠悠 岁月无言