如何为新添加的节点创建新的ID?
我通常可以获取默认树节点的 ID,但我的问题是 onCreate,然后 jsTree 将添加一个新节点,但它没有 ID。我的问题是如何向新创建的树节点添加 ID?
我想做的是将 ID HTML 属性添加到新创建的树节点,但如何操作呢?
我需要获取所有节点的 ID,因为它将作为节点各自 div 存储的参考。
HTML 代码:
<div class="demo" id="demo_1">
<ul>
<li id="phtml_1" class="file"><a href="#"><ins> </ins>Root node 1</a></li>
<li id="phtml_2" class="file"><a href="#"><ins> </ins>Root node 2</a></li>
</ul>
</div>
JS 代码:
$("#demo_1").tree({
ui : {
theme_name : "apple"
},
callback : {
onrename : function (NODE, TREE_OBJ) {
alert(TREE_OBJ.get_text(NODE));
alert($(NODE).attr('id'));
}
}
});
干杯, 标记
I can normally get the ID of the default tree nodes but my problem is onCreate then jsTree will add a new node but it doesn't have an ID. My question is how can I add an ID to the newly created tree node?
What I'm thinking to do is adding the ID HTML attribute to the newly created tree node but how?
I need to get the ID of all of the nodes because it will serve as a reference for the node's respective div storage.
HTML code:
<div class="demo" id="demo_1">
<ul>
<li id="phtml_1" class="file"><a href="#"><ins> </ins>Root node 1</a></li>
<li id="phtml_2" class="file"><a href="#"><ins> </ins>Root node 2</a></li>
</ul>
</div>
JS code:
$("#demo_1").tree({
ui : {
theme_name : "apple"
},
callback : {
onrename : function (NODE, TREE_OBJ) {
alert(TREE_OBJ.get_text(NODE));
alert($(NODE).attr('id'));
}
}
});
Cheers,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有权访问该节点,您应该可以自己添加 ID:
If you have access to the node you should be able to add the ID by yourself: