微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

js jQuery分组数据

<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">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 = $$.g<a href="https://www.jb51.cc/tag/eto/" target="_blank" class="keywords">eto</a>bj(data<a href="https://www.jb51.cc/tag/so/" target="_blank" class="keywords">.so</a>nProjectAppCategorys,'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 = $$.g<a href="https://www.jb51.cc/tag/eto/" target="_blank" class="keywords">eto</a>bj(data<a href="https://www.jb51.cc/tag/so/" target="_blank" class="keywords">.so</a>nProjectAppCategorys,elem_cht);
                                                    parent.childsList.push($.extend(true,child));
                                                });
                                                elem_c.childsList.push($.extend(true,parent));
                                            }
                                        }
                                    });
                                    if (elem_c.helmet == index_h &amp;&amp; elem_c.spId == elem_p.spId &amp;&amp; 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;
        };    

  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐