zoukankan      html  css  js  c++  java
  • 分级数组、显示分级菜单

    public function build($data,$parentid=0){//分级数组
    $tree=[];
    foreach ($data as $node){
    if($node["parentid"]==$parentid){
    $children = $this->build($data,$node['id']);
    if($children){
    $node["children"] = $children;
    }
    $tree[] = $node;
    }
    }
    return $tree;
    }

    public function menuView($tree, $children=false) {//显示菜单
    if ($children)
    $template .= "<ul class="sub-menu">";
    foreach($tree as $k=>$node) {
    // 当前记录有子
    if ($node['children']) {
    $template .= "<li class="nav-link nav-toggle"><a class="nav-link " href="javascript:;"><span class="title">".$node['menuname']."</span></a>";
    $template .= $this->menuView($node['children'], true);
    $template .= "</li>";
    } else {
    // 当前记录没有子,加上链接
    $template .= "<li class="nav-item"><a href="index.php?".$node['router'].""><span class="title">".$node['menuname'] . "</span></a></li>";
    }
    }
    if ($children)
    $template .= "</ul>";
    return $template;
    }

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    剑指offer-栈的压入、弹出序列
    剑指offer-包含min函数的栈
    图-Dijkster最短路径
    剑指offer-顺时针打印矩阵
    二叉树的镜像
    剑指offer-树的子结构
  • 原文地址:https://www.cnblogs.com/xdingc/p/6856154.html
Copyright © 2011-2022 走看看