其他分享
首页 > 其他分享> > dtree完成展开关闭功能

dtree完成展开关闭功能

作者:互联网

需求:当页面显示 展开 字段时,dtree结构展开,当页面显示 关闭 字段时,dtree结构关闭

如下图:
在这里插入图片描述
在这里插入图片描述
后台代码:

@RestController
@RequestMapping("dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    //展示树形结构
    @RequestMapping("buildLeftTree")
    public DataGridView buildLeftTree(){

      List<Dept>deptList=deptService.queryDeptList();

      List<DeptNode>treeNodeList = new ArrayList<>();
        for (Dept dept : deptList) {
            //spread是用于判断是 true : false
            // dept.getOpen()   open 是  是否展开字段
            Boolean spread= dept.getOpen() == 1 ? true : false;
             
             treeNodeList.add(new DeptNode(dept.getId(),dept.getPid(),dept.getTitle(),spread));
        }
        return new DataGridView(treeNodeList);
    }
@Data
@NoArgsConstructor
public class DeptNode {
    private Integer id;
    private Integer parentId;
    private String title;
    private Boolean spread;

    public DeptNode(Integer id, Integer parentId, String title,Boolean spread) {
        this.id = id;
        this.parentId = parentId;
        this.title = title;
        this.spread=spread;
    }
}

标签:dtree,title,private,id,dept,spread,关闭,parentId,展开
来源: https://blog.csdn.net/jq1223/article/details/112597002