web123456

layui check not linked to the parent item tree control_layui tree component to reproduce the check process approach

layuiProvides two ways to initialize the selected state of a node

one ('demoId', [2,13,18,19]); //batch check nodes with id 2,13,18,19

where 19 is the node ID of the actual node checked by the user, but the checked node submitted by the component contains the full path.

If the top level permissions are checked, then the layui settings node will have all of its permissions checked when it is checked, which means that all permissions are checked by default.

The layui tree component can't reproduce the user's node checkmarks at this point, what should I do?

At this point it's not possible to solve the problem from the frontend's point of view, because that's the way the rules of the layui tree component work.

II Setting the initial selection status by data source

Does this mean that we can set the checked attribute of nodes 2, 13, 18, and 19 to true? No. If the checked attribute of the top-level permission is true, it means that all permissions are initially checked.

Now let's revisit the process of using the tree component: the

We want to give a role access to a list of roles, so the component selects the list of roles and the ancestor node.

Of course, if we check the backend roles, then the list of child roles will also be checked.

If the target child node has no siblings, the data checked by the component is the same for both selection methods.

Selecting descendant nodes by checking the parent node can improve the efficiency of checking, that's all.

The entire process of using the attribute component, we need to care about is always only leaf nodes, which is the core logic of the node initialization selected state, that is to say, we put the user to the real check, the leaf nodes, 19 set into the check state on it.

Way 1, set the checked attribute of the leaf node checked in the data source to true, the

foreach ($res as $key => $value){

//whether there are child nodes

$count = AdminPrivileges::where([['pid','=',$value['id']],['status','=','1001']])->count();

if(in_array($value['id'],$privileges)&&$count==0){

$res[$key]['checked'] = true;

}else{

$res[$key]['checked'] = false;

}

unset($res[$key]['level']);

if($count!=0){

$temp = $this->get_lower_i($where,$value['id'],$privileges);

$res[$key]['children'] = $temp;

}

}

Way 2, pass, with the second argument being the checked leaf node.

('demoId', [19]);