gpt4 book ai didi

javascript - 使用 jsTree 在最深节点中创建到 Controller 的链接?

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

我正在使用http://www.jstree.com/在 asp.net mvc 中。

我想要一个树结构,用户可以单击最深的节点并在我的网站上导航。树结构可以工作,但我无法在其中创建任何链接(url)。

我在 View 中有此代码

<script>
var j = jQuery.noConflict();
j(function () {
j("#jstree_demo_div").jstree({
"plugins": ["search"]
});

var to = false;
j('#plugins4_q').keyup(function () {
if (to) { clearTimeout(to); }
to = setTimeout(function () {
var v = j('#plugins4_q').val();
j('#jstree_demo_div').jstree(true).search(v);
}, 250);
});

});
</script>

<div id="jstree_demo_div">
<ul id="tree">
<li>
@if (Model != null) {
<a href="#">@Model.CategoryName</a>
@Html.Partial("_CategoryChildren", Model)
}
</li>
</ul>
</div>

和部分 View CategoryChildren

@foreach (var item in Model.Children)
{
<ul>
@if (item != null)
{
<li id="@item.CategoryID">

<a href="#" class="cat">@item.CategoryName</a>
@if (item.Children.Count > 0)
{
@Html.Partial("_CategoryChildren", item)
}
</li>
}
</ul>
}

我尝试将部分 View 中的 href="#" 编辑为 www.google.com,但当我单击该节点时没有任何反应。

我的最终目标是,当用户单击最深的节点时,我想将 @Model.ParentCategoryID 发送到 Controller ,并过滤掉具有该 @Model.ParentCategoryID 的所有值到 View 。

最佳答案

使用select_node.jstree处理程序:

j("#jstree_demo_div").on('select_node.jstree', function (e, data) {
console.log(data.node.a_attr.href); // do whatever you need with this value
});

关于javascript - 使用 jsTree 在最深节点中创建到 Controller 的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30660465/

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