美文网首页
树形结构横向的,类似脑图

树形结构横向的,类似脑图

作者: 路灯下de男孩 | 来源:发表于2018-09-28 14:47 被阅读0次
树形结构.png
  • 整体以原生js写成页面只有一个
    <div id="chart"></div>

  • 如图形式的横向树形结构,

// 数据结构
var ScriptManageObj = [{
        id: 1,
        name: 'A1',
        list: [
            {
                id: 11,
                name: 'B1',
                list: [
                    {
                        id: 111,
                        name: 'C1',
                        list: [{
                            id: 111,
                            name: 'D3',
                            list: []
                        },{
                            id: 111,
                            name: 'D4',
                            list: []
                        }]
                    },
                ]
            },
            {
                id: 12,
                name: 'B2',
                list: [{
                    id: 121,
                    name: 'C2',
                    list: []
                }]
            },
        ]
    }];
  • 整体样式如下
<style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            padding: 20px;
        }
        .table{
            /*overflow: hidden;*/
            white-space:nowrap;
        }
        .text-header{
            /*float: left;*/
            display: inline-block;
            white-space:nowrap;
            padding-bottom: 10px;
            padding-top: 10px;
            margin-left: 50px;
            margin-right:50px;
            position: relative;
        }
        .text-header>.after{
            content: '';
            height: 1px;
            width: 50px;
            background: red;
            position: absolute;
            left: 100%;
            top: 50%;
        }
        .text-header>.before{
            content: '';
            height: 1px;
            width: 50px;
            background: red;
            position: absolute;
            right: 100%;
            top: 50%;
        }
        .text-header>div{
            background-color: #000;
            color: #fff;
            width: 100px;
            height: 50px;
            text-align: center;
            line-height: 50px;

            /*margin-left: 20px;*/
            /*margin-bottom: 20px;*/
        }
        .content{
            /*float: left;*/
            display: inline-block;
            white-space:nowrap;

        }


        /*线条*/
        .line,.line-only{
            /*float: left;*/
            display: inline-block;
            white-space:nowrap;

        }
        .line>div,.line-only>div{
            height: 29px;
            width: 30px;
        }
        /* .table>.tr{
            border-left: 1px solid red;
        } */
        .tr>div{
            vertical-align: middle;
        }
        .tr{
            position: relative;
        }
        .tr>.tr_children{
            position: absolute;
            left: 0%;
            height: 100%;
            width: 1px;
            background: red;
            bottom: 0%;
            /* border-left: 1px solid red; */
        }
        .table>.tr:first-child>.tr_children{
            position: absolute;
            left: 0%;
            height: 50%;
            width: 1px;
            background: red;
            top: 50%;
        }
        .table>.tr:last-child>.tr_children{
            position: absolute;
            left: 0%;
            height: 50%;
            width: 1px;
            background: red;
            bottom: 50%;
        }
        .tr>.line>div:nth-of-type(1){
            display: inline-block;
            white-space:nowrap;

            border-left: 1px dashed red;
            border-bottom: 1px dashed red;
        }
        .tr>.line>div:nth-of-type(2){
            border-left: 1px dashed red;
        }
        .tr:nth-of-type(1)>.line>div:nth-of-type(1){
            border-left: none;
        }
        .tr:nth-last-child(1)>.line>div:nth-of-type(2){
            border-left: none;
        }
        .line-only>div:nth-of-type(1){
            border-bottom: 1px dashed red;
        }
    </style>
  • 最后就是写的方法了啊
    var chart = document.getElementById('chart');
    var mode1 = function(rowSpanNumber, obj) {
        var table = '<div class="table">';
        obj.forEach(function(item) {
            table += '<div class="tr">';
            if(obj.length>1){
                table += '<div class="tr_children"></div>';
            }
            table += '<div class="text-header">';
            if(rowSpanNumber===1){// 判断前面的横线要不要
                table += '<div class="before"></div>';
            }
            table +=  '<div>'+item.name+'</div>';
            if(item.list && item.list.length != 0) {// 判断后面的横线要不要
                table += '<div class="after"></div>';
            }
            table += '</div>';
            if(item.list && item.list.length != 0) {
                table += '<div class="content">';
                table += mode1(1, item.list);// 回调
                table += '</div>'
            }
            table += '</div>'
        });
        table += '</div>';
        return table;
    };
    chart.innerHTML = mode1(0, ScriptManageObj);// 调用对应的方法写进去就好了哈哈

整体就这些了哈哈

相关文章

  • 树形结构横向的,类似脑图

    整体以原生js写成页面只有一个 如图形式的横向树形结构, 整体样式如下 最后就是写的方法了啊 整体就这些了哈哈

  • GIT存储结构介绍

    一图流 简单介绍 Git 内部存储结构类似于Linux中文件系统的文件结构(树形结构),每个commit都指向一个...

  • 【产品工具】常用高效软件分享

    1、Xmind (百度脑图/Mindjet) 简介:思维导图软件, 可用来绘制树形图、逻辑图和组织结构图等等 用途...

  • 二叉树-树形结构

    一、树形结构 线性结构:数组、链表、栈、队列都是线性结构树形结构:类似于一颗树的形状,一个结点会有多个子结点。 结...

  • JS如何解析不规则动态深度的Json树结构

    如果单独问起Json和树形结构,想必大部分人都是很清楚,Json树结构类似以下结构,是Json格式的数据通过树形展...

  • 组合模式

    组合模式有时又叫部分-整体模式在处理类似树形结构的问题时比较方便,看看关系图: 直接来看代码: [java] vi...

  • 设计模式-组合模式(Composite)

    组合模式有时又叫部分-整体模式,在处理类似树形结构的问题时比较方便。 看看关系图: 直接来看代码: 使用场景:将多...

  • 数据结构分析之二叉树

    概述 在分析树形结构之前,先看一下树形结构在整个数据结构中的位置 当然,没有图,现在还没有足够的水平去分析图这种太...

  • js 数组与树形结构对象相互转换

    数组 树形结构对象 数组转成树形结构 树形结构转成数组

  • django 实现树形结构两种方式

    树形结构类似于数据结构中的二叉树,如果树形结构比较复杂的话,通过递归的方式查询并不是那么简介,多次 访问数据库查询...

网友评论

      本文标题:树形结构横向的,类似脑图

      本文链接:https://www.haomeiwen.com/subject/qxkpoftx.html