数据如下:
var selectSpec = [
{
attr: [{ '内存': 20 }], attrValues:
[{ attrValueName: '16G', attrValueId: 21 }, { attrValueName: '32G', attrValueId: 22 }]
},
{
attr: [{ '颜色': 27 }],attrValues:
[{ attrValueName: '白色', attrValueId: 23 }, { attrValueName: '黑色', attrValueId: 34 }]
}
];
需要通过算法得到如下结果:
var selectResult = [
[{ attrId: 20, attrValueId: 21, attrValueName: '16G' },
{
attrId: 27, attrValueId: 23, attrValueName: '白色'
}],
[{ attrId: 20, attrValueId: 21, attrValueName: '16G' },
{
attrId: 27, attrValueId: 34, attrValueName: '黑色'
}],
[{ attrId: 20, attrValueId: 22, attrValueName: '32G' },
{
attrId: 27, attrValueId: 23, attrValueName: '白色'
}],
[{ attrId: 20, attrValueId: 22, attrValueName: '32G' },
{
attrId: 27, attrValueId: 34, attrValueName: '黑色'
}]
];
请问算法怎么写?
已通过StackOverFlow提问解决,地址如下:
http://stackoverflow.com/questions/43245139/cartesian-product-with-js/43246369#43246369