Jstree 没有为 li 元素分配 id
我有一个 jstree 实例。它是ajax和json。
这是我创建树的方法。
$("#tree").jstree({
"plugins" : ["themes", "json_data", "ui"],
"json_data" : {
"ajax" : {
"type": 'GET',
"url": function (node) {
var nodeId = "";
var url = ""
if (node == -1)
{
//first url called is static
url = "myUrl";
}
else
{
//click on a node "li", get the id, append it to the url.
nodeId = node.attr('id');
url = "myUrl" + nodeId;
}
return url;
},
"success": function (new_data) {
//get the data topNode out of the json object
new_data = new_data.topNode;
return new_data;
}
}
},
});
这是输出。
<div id="tree" class="jstree-classic jstree jstree-0 jstree-focused jstree-default">
<ul>
<li class="jstree-closed jstree-last">
<ins class="jstree-icon"> </ins>
<a class="" href="#">Item 1</a>
</li>
</ul>
</div>
然而,当渲染树时,
I have an instance of jstree. It is ajax with json.
Here is how I am creating the tree.
$("#tree").jstree({
"plugins" : ["themes", "json_data", "ui"],
"json_data" : {
"ajax" : {
"type": 'GET',
"url": function (node) {
var nodeId = "";
var url = ""
if (node == -1)
{
//first url called is static
url = "myUrl";
}
else
{
//click on a node "li", get the id, append it to the url.
nodeId = node.attr('id');
url = "myUrl" + nodeId;
}
return url;
},
"success": function (new_data) {
//get the data topNode out of the json object
new_data = new_data.topNode;
return new_data;
}
}
},
});
Here is the output.
<div id="tree" class="jstree-classic jstree jstree-0 jstree-focused jstree-default">
<ul>
<li class="jstree-closed jstree-last">
<ins class="jstree-icon"> </ins>
<a class="" href="#">Item 1</a>
</li>
</ul>
</div>
However when the tree is rendered the <LI> element does not have an id. Should be automatically appended to the <LI>. What am i missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果下面是从 ajax 调用返回的数据,您需要将
"id":"1"
移动到 attributes 部分,这样它看起来像
If below is your data returned from ajax call you need to move
"id":"1"
to attributes sectionso it would look like
只需将属性更改为 attr,id 就会出现在“a”节点中。我还想要“li”节点中的 id,但直到现在我对元数据的尝试都没有成功。
从:
http://www.jstree.com/documentation/json_data
just change attributes to attr and an id will appear in the 'a' node. I also want the id in the 'li' node but until now my tries with metadata are not successful.
from:
http://www.jstree.com/documentation/json_data