zoukankan      html  css  js  c++  java
  • 搜索结果为树形结构的前端核心

    话不多说,直接上代码

                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);
  • 相关阅读:
    JS可改变列宽table
    无图片,用css border实现尖三角
    IE6下position:fixed;兼容
    巧用cssText属性批量操作样式
    Java
    Java
    Java
    JRebel
    Spring
    ActiveMQ
  • 原文地址:https://www.cnblogs.com/wangking/p/8393737.html
Copyright © 2011-2022 走看看