I have the following js input, an array of json objects selectSpec
var selectSpec = [
{
attr: [{ 'memory': 20 }],
attrValues:[
{ attrValueName: '16G', attrValueId: 21 },
{ attrValueName: '32G', attrValueId: 22 }
]
},
{
attr: [{ 'color': 27 }],attrValues:
[
{ attrValueName: 'white', attrValueId: 23 },
{ attrValueName: 'black', attrValueId: 34 }
]
}
];
I need to output an arry the following data,
var selectResult = [
[
{ attrId: 20, attrValueId: 21, attrValueName: '16G' },
{ attrId: 27, attrValueId: 23, attrValueName: 'white' }
],
[
{ attrId: 20, attrValueId: 21, attrValueName: '16G' },
{ attrId: 27, attrValueId: 34, attrValueName: 'black' }
],
[
{ attrId: 20, attrValueId: 22, attrValueName: '32G' },
{ attrId: 27, attrValueId: 23, attrValueName: 'black' }
],
[
{ attrId: 20, attrValueId: 22, attrValueName: '32G' },
{ attrId: 27, attrValueId: 34, attrValueName: 'white' }
]
];
I try to use cartesian product,but finally,it remains a little problems,I don't know how to achieve it.thanks in advance.