参数规格如下:
let specParam = [['红色','绿色','白色','黄色'], ['大,'小']]
js部分:
let getSpecParamCom = (specData, index) => {
for (let i = 0; i < specData[index].length; i++) {
tempResult[index] = specData[index][i];
if (index != specData.length - 1) {
getSpecParamCom(specData, index + 1);
} else {
result .push({
specItems: tempResult.join("|"), // 价格规格项
oriPrice: 0, // 原始价格
disPrice: 0, // 优惠价格
});
}
}
tempResult = [];
};
使用:
let tempResult = []
let result = []
let testData = [['红色','绿色','白色','黄色'],['大','小']]
getSpecParamCom(testData, 0)
结果: