**
ztree 在PHP 中的使用
**
html页面代码如下:
php 后台处理
public function radio(Request KaTeX parse error: Expected '}', got 'EOF' at end of input: … { if (request->isPost()) {
//部门
$uid = 3;
$dept = Db::table(‘department’)->field(‘id,name,parentid as pId’)->select();
$user_per = Db::table(‘user_person’)->field(‘dept_id’)->where(‘uid’,
u
i
d
)
−
>
s
e
l
e
c
t
(
)
;
/
/
判
断
这
个
部
门
是
否
被
选
中
f
o
r
e
a
c
h
(
uid)->select(); //判断这个部门是否被选中 foreach (
uid)−>select();//判断这个部门是否被选中foreach(dept as &$value) {
c
h
e
c
k
=
d
e
e
p
i
n
a
r
r
a
y
(
check = deep_in_array(
check=deepinarray(value[‘id’],
u
s
e
r
p
e
r
)
;
i
f
(
user_per); if (
userper);if(check) {
$value[‘checked’] = true;
KaTeX parse error: Expected 'EOF', got '}' at position 39: … }̲ } …value);
p
r
e
=
g
e
t
t
r
e
e
(
pre = gettree(
pre=gettree(dept);
return json($pre);
}
return $this->fetch(‘permission/checkbox’);
}
function gettree($array, $pid = 0)
{
a
r
r
=
[
]
;
f
o
r
e
a
c
h
(
arr = []; foreach (
arr=[];foreach(array as
k
e
y
=
>
key=>
key=>item) {
if ($item[‘pId’] == $pid) {
t
m
p
=
g
e
t
t
r
e
e
(
tmp = gettree(
tmp=gettree(array, $item[‘id’]);
$tmp && $item[‘children’] = $tmp;
$arr[] = $item;
}
}
return $arr;
}