The system involves the commodity, often has the specification existence, a commodity many specifications need to go to maintain, how through the JS way quickly constructs the product specification edit arrangement combination? The whole idea is the way to merge down by spec, the core JS code is as follows:
<script type= "Text/javascript" >functionTest () {varDoublearrays =[[{valId:"1", Valcode: "M", ValName: "Large Size"},{valid: "2", Valcode: "L", ValName: "Small Size"}],//spec. 1: Size[{valId: "3", Valcode: "R", ValName: "Red"},{valid: "4", Valcode: "W", ValName: "White"}],//spec. 2: Color[{valId: "5", Valcode: "C", ValName: "Long"},{valid: "6", Valcode: "D", ValName: "Short"}]//spec. 3: Length ]; varRET =Doexchange (doublearrays); Console.log (ret); document.write ("Total:" + ret.length + "kind of combination! <br/> "); for(vari = 0; i < ret.length; i++) {document.write (Ret[i]+ "<br/>"); } } functionDoexchange (doublearrays) {varLen =doublearrays.length; if(Len >= 2) { varLen1 = Doublearrays[0].length; varLen2 = doublearrays[1].length; varNewlen = Len1 *Len2; vartemp =NewArray (Newlen); varindex = 0; for(vari = 0; i < len1; i++) { for(varj = 0; J < Len2; J + +) {Temp[index]={valid:doublearrays[0][i].valid + "_" + doublearrays[1][j].valid, valcode:doublearrays[0][i].valcode + "_" + doublearrays[1][j].valcode, valname:doublearrays[0][i].valid + "_" + doublearrays[1][j].valname}; Index++; } } varNewArray =NewArray (len-1); newarray[0] =temp; if(Len > 2) { var_count = 1; for(vari=2;i<len;i++) {Newarray[_count]=Doublearrays[i]; _count++; }} console.log (NewArray); returnDoexchange (NewArray); } Else { returnDoublearrays[0]; }} test (); </script>
Example:
Product Multi-spec Model Construction Example