Product Multi-spec Model Construction Example

Source: Internet
Author: User

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>


Product Multi-spec Model Construction Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.