码迷,mamicode.com
首页 > Web开发 > 详细

生成sku js

时间:2015-01-09 18:49:05      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:

  <script type="text/javascript">

        //var array = [[‘红色‘, ‘黑色‘, ‘白色‘], [‘小号‘, ‘中号‘, ‘加大‘], [‘男‘, ‘女‘]];
        var array = [[‘5:红色‘], [‘7:M‘, ‘8:L‘]];
     
        var results = new Array(); //创建一个数组
        var len = array.length;
        var indexs = {};


        $(document).ready(function () {
            GetResults(-1);

            $("#cou").html("共有" + results.length + "种组合;<br/>");
            for (var a = 0; a < results.length; a++)
            {
                $("#list").append("<li>" + results[a] + "</li>");
            }
        });

        function GetResults(start) {
            start++;
            if (start > len - 1) {
                return;
            }
            if (!indexs[start]) {
                indexs[start] = 0;
            }
            if (!(array[start] instanceof Array)) {
                array[start] = [array[start]];
            }
            for (indexs[start] = 0; indexs[start] < array[start].length; indexs[start]++) {
                GetResults(start);
                if (start == len - 1) {
                    var temp = [];
                    for (var i = len - 1; i >= 0; i--) {
                        if (!(array[start - i] instanceof Array)) {
                            array[start - i] = [array[start - i]];
                        }
                        temp.push(array[start - i][indexs[start - i]]);
                    }
                    results.push(temp);
                }
            }

        }
    </script>

生成sku js

标签:

原文地址:http://www.cnblogs.com/zhangweixin/p/4213724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!