gpt4 book ai didi

javascript - 动态使点击的节点作为加载节点的父节点 - jsTree

转载 作者:行者123 更新时间:2023-11-28 08:44:44 25 4
gpt4 key购买 nike

我是 jsTree 的新手,我有 2 个问题。

*说明:*我有基于 id 和类型的许多层次结构的 jsTree,并且我正在尝试实现按需加载技术。在页面加载时,我仅显示第一个层次结构(根节点),没有子节点。然后,当我单击任何节点时,我会根据该特定节点的 id 和类型检索其子节点(采用 JSON 格式)。 jsTree 在浏览器上成功附加了层次结构,但它无法确认单击的节点是已加载节点的父节点(逻辑上我希望如此,因为我没有告诉 jsTree 这样做)。那么,现在我的问题来了:-

1)如何动态地将这个单击的节点作为这些加载节点的父节点?

2.) 我必须双击 jsTree 的节点才能加载相应的子节点。如何只需单击一下即可完成此操作?

提前致谢。

这是我的代码:

   In the Servlet, I have the following conditional statements:-

if(type.equals("root"))
{
String jsonString = TreeTest.getRoot().getString("data");
out.write(jsonString);
}
else if(type.equals("rig"))
{
String jsonString = TreeTest.getSecondHierarchy(Integer.parseInt(id)).getString("data");
out.write(jsonString);
}
else if(type.equals("well"))
{
String jsonString = TreeTest.getThirdHierarchy(Integer.parseInt(id)).getString("data");
out.write(jsonString);
}

我为每次调用返回的 JSONObject 的形式为

“数据”:{ “数据”:“节点名称”, “attr”:{“id”:node_id,“type”:“node_type”} }

<小时/>
        Here is my jsTree codes 

$(document).ready(function(){

$("#tree").jstree({

"themes": {"theme": "classic"},

"core" : {
"strings" : {
"loading" : "Loading data..."
}
},

"json_data": {


"ajax" : {
"type": 'GET',
"url": "TreeViewServlet",

"data": function(n)
{
return{
"id" : n.attr ? n.attr("id") : 0,
"type": n.attr? n.attr("type"): "root"
};

}

}
},


"types" : {
"types" : {

"rig" : {
"icon" : {
"image" : "./images/Rig.gif"
}
},
"well" : {
"icon" : {
"image" : "./images/Well.gif"
}
},

"assysystype" : {
"icon" : {
"image" : "./images/whxt.gif"
}
},
"assy" : {
"icon" : {
"image" : "./images/Assy.gif"
}
},

"_Drl-WH" : {
"icon" : {
"image" : "./images/w_icon.gif"
}
},
"_Compl-XT" : {
"icon" : {
"image" : "./images/x_icon.gif"
}
},

"subAssy" : {
"icon" : {
"image" : "./images/subass.gif"
}
}
}
},
"plugins" : ["themes","json_data","ui", "core", "types"]


}).delegate(".jstree-open>a", "click.jstree", function(event)
{
$.jstree._reference(this).close_node(this,false,false);
}).delegate(".jstree-closed>a", "click.jstree", function(event)
{
$.jstree._reference(this).open_node(this,false,false);
});
});

最佳答案

我解决了自己的问题并决定发布答案:-

1) 我必须获取单击节点的 ID 并将其发送到 Java Servlet,Servlet 然后处理请求并返回该节点的所有子节点的 JSON 字符串,然后使用 AJAX,将子节点附加回树。

2)有一把神奇的 key ,对于每个节点,我添加了 "state": "filled" 就这样了。

关于javascript - 动态使点击的节点作为加载节点的父节点 - jsTree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com