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

jstree 树默认选中子节点

程序员文章站 2022-07-13 16:10:34
...

  相信很多人都在为无法默认选中树节点而苦恼,弄出来了特意分享出来

 public Object Menu(String roleId, HttpServletRequest req) {
        List<SysMenu> list = menuService.query(Cnd.orderBy().asc("location").asc("path"));
        List<SysMenu> datas = roleService.getDatas();
        List<NutMap> menus = new ArrayList<>();
        List<SysMenu> roleMenus = roleService.getMenusAndButtons(roleId);//当前角色的权限
        for (SysMenu menu : list) {
            NutMap map = new NutMap();
            for (SysMenu bt : datas) {
                if (menu.getPath().equals(bt.getPath().substring(0, bt.getPath().length() - 4))) {
                    menu.setHasChildren(true);
                    break;
                }
            }
            for(SysMenu rm:roleMenus){
                if (menu.getId().equals(rm.getId())){
                    map.put("state", new State(false,false,true));//是否允许编辑-是否展开-是否选中树节点
                    break;
                }
            }
            map.put("id", menu.getId());
            map.put("text", menu.getName());
            map.put("icon", Strings.sBlank(menu.getIcon()));
            map.put("parent", "".equals(Strings.sNull(menu.getParentId())) ? "#" : menu.getParentId());
            map.put("data", menu.getHref());
            menus.add(map);
        }
        req.setAttribute("menus", Json.toJson(menus));
        return Strings.isBlank(roleId) ? null : roleService.fetch(roleId);
    }

 

public class State {
    private boolean disabled;
    private boolean opened;
    private boolean selected;

    /**
     * 树节点勾选
     * @param disabled  编辑
     * @param opened  是否展开
     * @param selected  是否选中
     */
    public State(boolean disabled,boolean opened,boolean selected){
        this.disabled=disabled;
        this.opened=opened;
        this.selected=selected;

    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public boolean isOpened() {
        return opened;
    }

    public void setOpened(boolean opened) {
        this.opened = opened;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
}

 

 

 

相关标签: jstree html java