阅读背景:

树形数据处理

来源:互联网 

数据库

Controller递归处理

public function getDeptTree() {
        $deptdata = Db::table('dept')->field('dept_name,dept_no,p_id')->select();
        $showdata = $this->getTree($deptdata, $p_id = 0, $depth = 0);
        $data = json($showdata);
        return $data;
    }
    // //部门树形数据组装
    public function getTree($treedata, $p_id, $depth) {
        $retnArr = array();
        if (!empty($treedata)) {
            foreach ($treedata as $key => $info) {
                if ($info['p_id'] == $p_id) {
                    $info['depth'] = $depth;
                    $temp_info = $info;
                    foreach ($treedata as $subinfo) {
                        if ($subinfo['p_id'] == $info['dept_no']) {
                            $temp_info['sub'] = $this->getDeptTree($treedata, $info['dept_no'], $depth + 1);
                        } 
                    }
                    $retnArr[] = $temp_info;
                } 
            } 

        } 
        return $retnArr;
    }
public function g



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: