js (jQuery)分组数据

2018-06-24 01:17:21来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

function getobjArr  (data) {
                var result = [];
                data.HELMET.system = '系统分类'
                // console.log(data)
                $.each(data.HELMET, function (index_h, elem_h) {
                    var h = {
                        id: index_h,
                        name: elem_h,
                        Projects: []
                    }
                    $(data.sonProjects).each(function (index_p, elem_p) {
                        elem_p.AppCategorys = [];
                        if (elem_p.sysCategory == 1) {
                            if (index_h == 'system') {
                                h.Projects.push(elem_p);
                            }
                        } else {
                            if (index_h != 'system') {
                                $(data.sonProjectAppCategorys).each(function (index_c, elem_c) {
                                    elem_c.childsList = [];
                                    if (elem_c.childs == '0') {
                                        if (elem_c.helmet == index_h && elem_c.spId == elem_p.spId && elem_c.pId == 0) {
                                            elem_p.AppCategorys.push(elem_c);

                                            // console.log(elem_p.AppCategorys)
                                        }
                                    } else {
                                        $(elem_c.childs.split(',')).each(function (index_ch, elem_ch) {
                                            var parent = $$.getobj(data.sonProjectAppCategorys, 'spacId', elem_ch);
                                            if (parent) {
                                                parent.childsList = [];
                                                if (parent.childs == '0') {
                                                    elem_c.childsList.push($.extend(true, {}, parent));
                                                } else {
                                                    $(parent.childs.split(',')).each(function (index_cht, elem_cht) {
                                                        var child = $$.getobj(data.sonProjectAppCategorys, 'spacId', elem_cht);
                                                        parent.childsList.push($.extend(true, {}, child));
                                                    });
                                                    elem_c.childsList.push($.extend(true, {}, parent));
                                                }
                                            }
                                        });
                                        if (elem_c.helmet == index_h && elem_c.spId == elem_p.spId && elem_c.pId == 0) { elem_p.AppCategorys.push(elem_c); }
                                    }
                                })

                                h.Projects.push(elem_p);
                            }
                        }
                    })
                    result.push($.extend(true, {}, h)); // 深复制
                })
                // console.log(result)
                return result;
            };    

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JS闭包

下一篇:JS 三维数组赋值