• 搜索结果为树形结构的前端核心


    话不多说,直接上代码

                function treeMenu(a){
                           this.tree=a||[];
                           this.groups={};
                        };
                        treeMenu.prototype={
                            init:function(pid){
                                this.group();
                                return this.getDom(this.groups[pid]);
                            },
                            group:function(){
                                for(var i=0;i<this.tree.length;i++){
                                    if(this.groups[this.tree[i].pId]){
                                        this.groups[this.tree[i].pId].push(this.tree[i]);
                                    }else{
                                        this.groups[this.tree[i].pId]=[];
                                        this.groups[this.tree[i].pId].push(this.tree[i]);
                                    }
                                }
                                return this.groups;
                            },
                            getDom:function(a){
                                if(!a){return ''}
                                var html='
    <ul>
    ';
                                for(var i=0;i<a.length;i++){
                                    html+= '你的页面片段 比如<li></li>';
                                    html+=this.getDom(this.groups[a[i].id]);
                                    html+='</li>
    ';
                                };
                                html+='</ul>
    ';
                                return html;
                            }
                        };
                        var html=new treeMenu(res.data).init(0),
                        alert(html);
  • 相关阅读:
    文件的上传
    JSP基础知识
    AJAX
    Listener
    Filter(一)
    session
    网络爬虫(9)-xpath解析
    网络爬虫(8)-正则表达式
    网络爬虫(7)-beautifulSoup解析库
    网络爬虫(6)-Requests库
  • 原文地址:https://www.cnblogs.com/wangking/p/8393737.html
Copyright © 2020-2023  润新知