Javascript 使用AJAX调用获取子节点的JsTree jsTree测试 var json_data=[]; $(函数(){ $.get('url call here',函数(数据、状态){ var dataL=JSON.parse(data);//console.l

Javascript 使用AJAX调用获取子节点的JsTree jsTree测试 var json_data=[]; $(函数(){ $.get('url call here',函数(数据、状态){ var dataL=JSON.parse(data);//console.l,javascript,jquery,jstree,Javascript,Jquery,Jstree,使用AJAX调用获取子节点的JsTree jsTree测试 var json_data=[]; $(函数(){ $.get('url call here',函数(数据、状态){ var dataL=JSON.parse(data);//console.log(dataL); var obj={}; obj[“id”]=dataL[“guid”]; obj[“text”]=dataL[“name”]; obj[“父”]=“#”; 控制台日志(obj); json_data.push(obj);

使用AJAX调用获取子节点的JsTree

jsTree测试
var json_data=[];
$(函数(){
$.get('url call here',函数(数据、状态){
var dataL=JSON.parse(data);//console.log(dataL);
var obj={};
obj[“id”]=dataL[“guid”];
obj[“text”]=dataL[“name”];
obj[“父”]=“#”;
控制台日志(obj);
json_data.push(obj);
$('jstreee').jstree({'core':{
“数据”:json_数据
} });
});
});
$('#jstreee')。on(“changed.jstree”,函数(e,data){
log(“我们在函数中”);
console.log(data.selected);
var node_clicked=data.selected;
如果(单击节点==null){
单击节点=“wiprohdmforg04july2016”;
}
var url=“url Call Here=“+data.selected;
$.get(url、函数(数据、状态){
var dataP=JSON.parse(数据);
日志(dataP.nodes);
var childlist=[];
log(dataP.nodes.length);
对于(var i=0;iRoot


jsTree测试
var json_data=[];var ten=0;
$(函数(){
$.get('**根节点url此处**',函数(数据、状态){
var dataL=JSON.parse(data);//console.log(dataL);
var obj={};
obj[“id”]=dataL[“guid”];
obj[“text”]=dataL[“name”];
obj[“父”]=“#”;
控制台日志(obj);
json_data.push(obj);
$('#jstreee').jstree({
“核心”:{
“数据”:json_数据
}
});
});
});
$('#jstreee')。在(“select_node.jstree”,function(e,data){
log(“我们在函数中”);
var node_clicked=data.selected[0];
var url=“**此处的url**”+单击节点;
$.get(url、函数(数据、状态){
控制台日志(数据);
if(data.nodes!==null){
var dataP=JSON.parse(数据);
日志(dataP.nodes);
var childlist=[];
log(dataP.nodes.length);
对于(变量i=0;i

jsTree测试
var json_data=[];var ten=0;
$(函数(){
$.get('**根节点url此处**',函数(数据、状态){
var dataL=JSON.parse(data);//console.log(dataL);
var obj={};
obj[“id”]=dataL[“guid”];
obj[“text”]=dataL[“name”];
obj[“父”]=“#”;
控制台日志(obj);
json_data.push(obj);
$('#jstreee').jstree({
“核心”:{
“数据”:json_数据
}
});
});
});
$('#jstreee')。在(“select_node.jstree”,function(e,data){
log(“我们在函数中”);
var node_clicked=data.selected[0];
var url=“**此处的url**”+单击节点;
$.get(url、函数(数据、状态){
控制台日志(数据);
if(data.nodes!==null){
var dataP=JSON.parse(数据);
日志(dataP.nodes);
var childlist=[];
log(dataP.nodes.length);
对于(var i=0;i
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsTree test</title>
<!-- 2 load the theme CSS file -->
<link rel="stylesheet"     href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
</head>
<body>
<!-- 3 setup a container element -->
<div id="jstreee">
</div>


<!-- 4 include the jQuery library -->
<script  src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js">       </script>
<!-- 5 include the minified jstree source -->
<script  src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js">   </script>
<script>
var json_data = [];
$(function () {

$.get('url call here',function(data,status){

var dataL = JSON.parse(data);//console.log(dataL);
var obj = {};
obj["id"]=dataL["guid"];
obj["text"]=dataL["name"];
obj["parent"]="#";
console.log(obj);
json_data.push(obj);
$('#jstreee').jstree({ 'core' : {
'data' : json_data
} });
});
});

$('#jstreee').on("changed.jstree", function (e, data) {
console.log("we are in the function");
console.log(data.selected);
var node_clicked = data.selected;
if (node_clicked == null) {
  node_clicked = "wiprohdmforg04july2016";
}
var url = "URL Call Here="+data.selected;
$.get(url,function(data,status){
var dataP = JSON.parse(data);
console.log(dataP.nodes);
var childlist = [];
console.log(dataP.nodes.length);
for(var i=0;i<dataP.nodes.length;i++){
var obj={};
obj["id"]=dataP.nodes[i].guid;
obj["text"]=dataP.nodes[i].name;
obj["parent"]=node_clicked;
//console.log("obj",obj);
var flag=0;
for(var j=0;j<json_data.length;j++){
if(obj["id"]===json_data[j]["id"]){
flag=1;
}
}
if(flag == 0){
json_data.push(obj);
}
console.log(json_data);
}
});
$('#jstreee').jstree(true).settings.core.data = json_data;
console.log("I reached here");
$('#jstreee').jstree(true).refresh(true);
});

</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsTree test</title>
<!-- 2 load the theme CSS file -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.m in.css" />
</head>
<body>
<!-- 3 setup a container element -->
<div id="jstreee">
</div>


<!-- 4 include the jQuery library -->
<script   src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js">  </script>
<!-- 5 include the minified jstree source -->
<script   src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js">     </script>
<script>
var json_data = [];var ten= 0;

$(function () {

$.get('**root node url here**',function(data,status){

var dataL = JSON.parse(data);//console.log(dataL);
var obj = {};
obj["id"]=dataL["guid"];
obj["text"]=dataL["name"];
obj["parent"]="#";
console.log(obj);
json_data.push(obj);
$('#jstreee').jstree({
'core' : {
'data' : json_data
}
});
});
});
$('#jstreee').on("select_node.jstree", function (e, data) {
console.log("we are in the function");
var node_clicked = data.selected[0];
var url = "**your url here**"+node_clicked;
$.get(url,function(data,status){
console.log(data);
if (data.nodes !== null) {
var dataP = JSON.parse(data);
console.log(dataP.nodes);
var childlist = [];
console.log(dataP.nodes.length);
for(var i=0;i<dataP.nodes.length;i++){
var obj={};
obj["id"]=dataP.nodes[i].guid;
obj["text"]=dataP.nodes[i].name;
obj["parent"]=node_clicked;
//console.log("obj",obj);
var flag=0;
for(var j=0;j<json_data.length;j++){
if(obj["id"]===json_data[j]["id"]){
flag=1;
}
}
if(flag == 0){
json_data.push(obj);
ten = 0;
}
console.log(json_data);
}
refreshh();
}
});

function refreshh(){
$('#jstreee').jstree(true).settings.core.data = json_data;
console.log("I reached here");

if(ten == 0){
$('#jstreee').jstree(true).refresh(true);
ten = 1;
}
}
});


</script>
</body>
</html>