参见红色部分: arrays[i].iconSkin 是后台传的图标数据,分别是root A A1 A2
$("#jstree_demo")
.jstree({
"core" : {
"animation" : 0,
"check_callback" : true,
'force_text' : true,
"themes" : { "stripes" : true },
// so that create works
"check_callback" : true,
'data' : function (obj, callback) {
var jsonstr="[]";
var jsonarray = eval('('+jsonstr+')');
$.ajax({
type: "POST",
url:url,
dataType:"json",
async: false,
success:function(result) {
var arrays= result;
for(var i=0 ; i<arrays.length; i++){
console.log(Object.getOwnPropertyNames(arrays[i]).sort());
var arr = {
"id":arrays[i].id,
"parent":arrays[i].pid==""?"#":arrays[i].pid,
"text":arrays[i].name,
"type":arrays[i].iconSkin,
"state": {"opened" : true,"selected":true}
//"state": {"selected":true}
}
jsonarray.push(arr);
}
}
});
callback.call(this, jsonarray);
}
},
"types" : {
"root": {
"icon" : "${pageContext.request.contextPath}/scripts/image/root.png"
},
"A": {
"icon" : "${pageContext.request.contextPath}/scripts/image/A.png"
},
"A1": {
"icon" : "${pageContext.request.contextPath}/scripts/image/A1.png"
},
"A2": {
"icon" : "${pageContext.request.contextPath}/scripts/image/A2.png"
}
},
"plugins" : [ "search", "state", "types", "wholerow","checkbox" ]
});