JSTREE生成树

来源:互联网 发布:win7恢复网络设置方法 编辑:程序博客网 时间:2024/06/07 16:33

在列表中需要树状列表,考虑后使用jstree生成

 (function(){        jstree = $('#jstree').jstree({            "core" : {                "animation" : 0,                "check_callback" : true,                "themes" : { "stripes" : true },                "data" : {                    "url" : function (node) {                        return ctx+"/sz/list";                    },                    "data" : function (node) {                        return { "id" : node.id };                    },                }},            "types" : {                "file" : {                    "icon" : "glyphicon glyphicon-user",                    "valid_children" : []                }            }        });        $('#jstree').bind("activate_node.jstree", function (obj, e) {            var menuText = e.node.text;            if(menuText){menuUserName=menuText;}        });        $('#jstree').bind("ready.jstree", function (obj, e) {            //该事件未树加载完成后执行事件,具体参考jstreeAPI        });
除此生成以外:

设置选择和去除选中状态

$('#jstree').jstree('select_node', menuUserName_id[glxss]);
$('#jstree').jstree('deselect_node',menuUserName_id[glxss]);

jstree 官网有详细的api 请查看



后台数据库的list 封装的model

import java.io.Serializable;/** * Created by cxj on 2017/2/7. */public class JsTree implements Serializable{    private String icon;    private String type;    private String id;    private String parent;    private String text;    public String getIcon() {        return icon;    }    public void setIcon(String icon) {        this.icon = icon;    }    public String getType() {        return type;    }    public void setType(String type) {        this.type = type;    }    public String getId() {        return id;    }    public void setId(String id) {        this.id = id;    }    public String getParent() {        return parent;    }    public void setParent(String parent) {        this.parent = parent;    }    public String getText() {        return text;    }    public void setText(String text) {        this.text = text;    }    @Override    public String toString() {        return "JsTree{" +                "id=" + id +                ", parent='" + parent + '\'' +                ", text='" + text + '\'' +                '}';    }    public JsTree(String id, String parent, String text) {        this.id = id;        this.parent = parent;        this.text = text;        this.icon="icon-user"; //默认图标        this.type="default";    }}


0 0
原创粉丝点击