SOURCE

console 命令行工具 X clear

                    
>
console
// 树结构 nodes = [node, node, node , ...]
// 节点  node = { id, label, children: [node, node] } 
// 如果是叶子节点, children = undefined

function searchTree(nodes, searchKey) {
    const nodeMap = new Map()

    const bfs = (arr) => {
        for(let i = 0; i < arr.length; i++) {
            nodeMap.set(arr[i].label, arr[i]);
            if(arr[i].children) {
                bfs(arr[i].children)
            }
        }
    }
    bfs(nodes);

    const { id } = nodeMap.get(searchKey) || {id:null};

    return id

}

const nodes = [
    {
        id: 1,
        label: '我',
        children: [
            {
                id: 2,
                label: '发',
                children: [
                    {
                        id: 3,
                        label: '啊',
                        children: [

                        ]
                    },
                    {
                        id: 4,
                        label: '是',
                        children: [

                        ]
                    },
                    {
                        id: 5,
                        label: '里',
                        children: [

                        ]
                    }
                ]
            }
        ]
    },
    {
        id: 6,
        label: '你'
    }
]

console.log(searchTree(nodes, '是d'))
<div class="container"> 
    <div class="left">这是左边栏</div>
    <div class="middle">这是中间烂</div>
    <div class="right">这是右边栏</div>
</div>
.container {
    position: relative
}

.left {
    float: left;
    width: 200px;
    background: #ccc;
}

.middle {
    background: yellow;
    overflow: auto;
    margin-right: 100px
}

.right {
    float: right;
    background: red;
    width: 100px;
    position: absolute;
    top: 0;
    right: 0;
}