gpt4 book ai didi

javascript - 从 jstree 中获取选定的节点

转载 作者:数据小太阳 更新时间:2023-10-29 04:22:35 25 4
gpt4 key购买 nike

我正在尝试从 jstree 中获取选定的节点。

这是 View 中的代码

<div id="divtree" >
<ul id="tree" >
@foreach (var m in Model.presidentList)
{
<li class="jstree-clicked">
<a href="#" class="usr">@m.Name</a>
@Html.Partial("Childrens", m)
</li>
}
</ul>
</div>

这是我尝试检索节点名称的 javascript 部分

$(".jstree-clicked").click(function (e) {
var node = $(this).jstree('get_selected').text();
alert(node);
});

我在仅获取选定节点时遇到问题。如果我选择其中一个子节点(例如树的最后一个节点),我仍然会得到整个节点列表。如果您知道我哪里做错了,请告诉我?

最佳答案

我认为您不应该为每个

  • 节点分配“jstree-clicked”类。并使用用于 jstree 绑定(bind)的 jstree 容器获取选定的节点。

    console.log($("#divtree").jstree("get_selected").text());

  • 关于javascript - 从 jstree 中获取选定的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20053868/

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