TreeView - 通过客户端动态添加节点

发布于 2024-12-25 14:59:28 字数 1321 浏览 3 评论 0原文

我刚刚开始使用 Telerik asp.net mvc,并且一直试图通过 javascript 将节点添加到树视图...但我在文档中没有看到任何可能的内容。任何人都这样做过,或者也许可以指出在哪里可以找到文档或示例的正确方向?

这是我用来设置树视图的代码:

@using (Html.BeginForm("Index", "Listings", FormMethod.Post, new { id = "frmListings", name = "frmListings" }))
    { 
        @(Html.Telerik().TreeView()
        .Name("topics")
        .ClientEvents(e => e.OnSelect("onSelect"))
        .BindTo(Model.Topics, mappings => mappings.For<Topic>(binding => binding
                                                .ItemDataBound((item, category) =>
                                                                {
                                                                    item.Text = category.Name;
                                                                    item.Value = category.URI + "|" + category.Id.ToString();
                                                                    item.Selected = (Model.CurrentCategory.Id == category.Id);
                                                                    //item.Expanded = item.Selected;
                                                                })
                                                .Children(category => category.Children)
                                              ))
        )

    }

I'm just starting to use the Telerik asp.net mvc and I'm stuck on trying to add a node to the tree view via javascript... but I don't see anything in the documentation where this is possible. Anyone done this or maybe can point in the right direction where to find docs or examples?

Here is the code I used to setup the treeview:

@using (Html.BeginForm("Index", "Listings", FormMethod.Post, new { id = "frmListings", name = "frmListings" }))
    { 
        @(Html.Telerik().TreeView()
        .Name("topics")
        .ClientEvents(e => e.OnSelect("onSelect"))
        .BindTo(Model.Topics, mappings => mappings.For<Topic>(binding => binding
                                                .ItemDataBound((item, category) =>
                                                                {
                                                                    item.Text = category.Name;
                                                                    item.Value = category.URI + "|" + category.Id.ToString();
                                                                    item.Selected = (Model.CurrentCategory.Id == category.Id);
                                                                    //item.Expanded = item.Selected;
                                                                })
                                                .Children(category => category.Children)
                                              ))
        )

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜警司 2025-01-01 14:59:28

目前,截至 2011 年第 3 季度 SP1,没有用于在 TreeView 中添加或删除节点的客户端 API。然而,这已记录在 Telerik 的公共问题跟踪系统 (PITS) 就在这里。如果您想在即将发布的版本中看到此功能,那么添加对该问题的评论会很有帮助。

同时,如果这只是为了添加节点的视觉效果,您可以查看 TreeView 生成的 HTML,并通过利用 JavaScript 进行一些 HTML 操作来添加您自己的元素。 TreeView 的核心只是一个

    元素,其中包含代表节点的各个

  • 元素,因此您可以继续添加自己的
  • 元素。然而,这不会反映在 TreeView 的数据中。

Currently, as of Q3 2011 SP1, there is no client-side API for adding or removing nodes from the TreeView. This has however been logged in Telerik's Public Issue Tracking System (PITS) right here. If you want to see this feature in an upcoming release voting adding a commenting on the issue helps greatly.

In the meantime, if this is just for the visual of adding nodes, you can take a look at the HTML generated by the TreeView and add your own elements by doing some HTML manipulation utilizing JavaScript. The TreeView at its core is just a <ul> element with individual <li> elements representing the nodes, so you could go ahead and add your own <li> elements. This will not be reflected in the TreeView's data however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文