First create a method in common under application. Here we take the department data table department as an example.
The database table structure is as follows:
Find the following sub-departments and output them in tree form. The code in common is:
function GetMenuID($pid){
$list = \think\Db::table("department")
->where("pid",$pid)
-->select();
return $list;
}
$list = Db::table('bumen')->where('pid',0)->select();//Find the parent column
$ this->assign("list",$list);
return $this->fetch();
<select class="layui-select" name="dpid" id="dpid" required="required" lay-verify="dpid" autocomplete="off">
{volist name="list" id="vo "}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ##" id="po"}
name="$po['id']|GetMenuID=
" id="co"}
; |——{$co.dp_name}</option>
##Only three levels are written here. If there are more levels, and so on, the output results are as follows: