zoukankan      html  css  js  c++  java
  • 左侧树无限层级算法

    /*
    * 暂时没想到好的算法,先这样
    *
    */

    public function getDpInfoAllByTreeGet(){
    $rs = $this->_getDpInfoAllByTree();
    $rs = $this->_getDpInfoAllByTreeGet($rs);
    $arr['title'] = '已授权用户';
    $arr['id'] = '';
    $arr['level'] = 0;
    $arr['dep_no'] = '';
    array_unshift($rs,$arr);
    $arr['children'] = $rs;
    return $rs;


    }


    //树形结构算法优化

    public function _getDpInfoAllByTreeGet(&$rs){
    foreach ($rs as $key => &$val){
    if(isset($val['children'])){
    $this->_changeStructure($val['children']);
    $this->_getDpInfoAllByTreeGet($val['children']);
    }
    }
    return $rs;
    }




    /*
    * 没有用户的部门树信息,左侧菜单栏数据
    */
    private function _getDpInfoAllByTree(){
    $rsDp = DB::table('department')
    ->select('dep_name as title','id','level','dep_no')
    ->orderBy('dep_no', 'asc','level')
    ->get()
    ->toArray();


    // var_dump($rsDp);exit;

    $level = DB::table('department')->max('level');//从数据库获取最大层数
    for ($i = 0; $i < $level; $i++) {
    $rsDp = $this->_getDpInfoAll($rsDp);
    }
    foreach ($rsDp as $key => $val) {
    if ($val['level'] != 1) {
    unset($rsDp[$key]);
    }
    }
    sort($rsDp);
    return $rsDp;
    }


    private function _getDpInfoALl($rsDp){
    $data = $rsDp;
    foreach ($rsDp as $key => $val) {
    for ($i = $key+1; $i < count($rsDp); $i++) {
    if (strpos($rsDp[$i]['dep_no'], $rsDp[$key]['dep_no']) !== FALSE && $rsDp[$i]['level'] == ($rsDp[$key]['level'] + 1)) {
    $now_level = $rsDp[$key]['level'] + 1;
    $data[$key]['children'][$now_level][$rsDp[$i]['dep_no']] = $rsDp[$i];
    }
    }
    }
    return $data;
    }
  • 相关阅读:
    Android 源码阅读之MMS细读TransactionService.java
    [Java2 入门经典]第16章 线程
    Android 源码阅读之建立3G网络流程
    从架构上看Android多媒体播放器
    Android 开发日志之仿三星Launcher
    非常适合OA系统的菜单
    模拟动网当前位置下拉菜单
    模拟windows菜单选项卡效果
    TreeView的各种操作
    ASCII表
  • 原文地址:https://www.cnblogs.com/best-jobs/p/9140961.html
Copyright © 2011-2022 走看看