我是jstree的新手并尝试通过JSON url加载树。子元素存在于另一个URL中以访问该URL,父ID需要附加到基本URL。我正在获取根节点但不是子元素。
<html>
<head>
<script src="jquery.js"></script>
<script src="jquery.jstree.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<script>
$(function () {
var list=[];
var list2=[];
var genreId=6628;
var state="";
var name=[];
var j=0;
$("#geo").click(function(n){
var url="my url";
if (n){
name[0]=0;
if(name[j] !="undefined"){
//alert(n.attr("name"));
genreId=name[j];
j++;
}
}
url=url+genreId;
$.getJSON(url,function(data){
var docs= data.response.docs;
for (var i = 0; i < docs.length; i++) {
var state= "closed";
list2.push({"data": docs[i].description ,"attr" : { "name" : docs[i].id },"state":state});
name[i]=docs[i].id;
}
});
$("#demo1").jstree({
"json_data" : {
"data" : list2
},
"plugins" : [ "themes", "json_data", "ui" ]
});
});
});
</script>
</head>
<body>
<button id="geo">get json</button>
<div id="demo1"></div>
</body>
</html>