在列表中需要樹狀列表,考慮後使用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";
}
}