`
/** * 获取数据 */ public function getList(){ $sec=$this->getSectionChild(0); //print_r($sec); echo json_encode($sec); }
/** * 获取子节点[递归] * @param $sec_id * @return mixed */ public function getSectionChild($id){ $section=M($this->tColumn)->where(array('column_pid'=>$id))->select(); ##是否为 0 foreach ($section as $key=>$val){ ##组装数据 $data[$key]['text']=$val['col_name']; $data[$key]['val']=$val['column_id'];
$child=$this->getSectionChild($val['column_id']);
if(!is_null($child)){
$section[$key]['nodes']=$child;//源数据
##组装数据
$data[$key]['nodes']=$child;
}
}
return $data;//返回组装数据
}
}`