jstree tree selects child nodes by default

  I believe that many people are distressed by the inability to select tree nodes by default, so I came up with it and shared it on purpose

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);//Permissions of the current role
        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));//Whether editing is allowed - whether to expand - whether to select the tree node
                    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;

    /**
     * tree node check
     * @param disabled edit
     * @param opened whether to expand
     * @param selected is 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;
    }
}

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327030714&siteId=291194637
Recommended