欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

bootstrap treeview 菜单树 最详细

程序员文章站 2022-03-04 11:48:26
...

实体类
@Data
public class BootTree {
private Integer id;
private String text;
private Integer pid;
private Boolean selectable;
private List nodes;
private String href;
}
controller 层
@RequestMapping(“getBootTree”)
@ResponseBody
public List getBootTree(){
List treelist = orderService.getBootTree();
return treelist;
}
service 接口
List getBootTree();

service 实现类

@Override
public List getBootTree() {
int pid = -1;
List bootTrees = getBootTreeNodes(pid);
return bootTrees;
}

private List<BootTree> getBootTreeNodes(Integer pid) {
    List<BootTree> bootTrees = orderMapper.getBootTreeNodes(pid);
    for (BootTree bootTreeBean : bootTrees) {
        Integer id2 = bootTreeBean.getId();
        List<BootTree> bootTreeNode = getBootTreeNodes(id2);
        if (bootTreeNode == null || bootTreeNode.size() <= 0) {
            bootTreeBean.setSelectable(true);
        }else {
            bootTreeBean.setSelectable(false);
            bootTreeBean.setNodes(bootTreeNode);
        }
    }
    return bootTrees;
}

mapper 层
@Select(“select * from springboot.t_tree where pid = #{pid}”)
List getBootTreeNodes(int pid);

前台 页面

$(function(){
initMyTree();
})
function initMyTree(){
$.ajax({
url:’…/order/getBootTree’,
type:‘post’,
data:{},
dataType:‘json’,
success:function(result){
$(’#myTree’).treeview({
data:result,
onNodeSelected:function(event,node){
$.addtabs({iframeHeight: 650});
$.addtabs.add({
id:node.id,
title:node.text,
url:node.href
});
}
})
}
})

}
相关标签: bootstrap treeview