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;
    }

  • 相关阅读:
    外观模式
    享元模式
    c#中的抽象类和接口
    装饰者模式
    组合模式
    适配器模式
    springboot 源码篇002## web层自动装配部分源码
    springboot 源码篇002## 自动装配原理
    springboot 源码篇 01
    shell 脚本基础 第二篇
  • 原文地址:https://www.cnblogs.com/xdingc/p/6856154.html
Copyright © 2011-2022 走看看