TreeView - 通过客户端动态添加节点
我刚刚开始使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,截至 2011 年第 3 季度 SP1,没有用于在 TreeView 中添加或删除节点的客户端 API。然而,这已记录在 Telerik 的公共问题跟踪系统 (PITS) 就在这里。如果您想在即将发布的版本中看到此功能,那么添加对该问题的评论会很有帮助。
同时,如果这只是为了添加节点的视觉效果,您可以查看 TreeView 生成的 HTML,并通过利用 JavaScript 进行一些 HTML 操作来添加您自己的元素。 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.