简体   繁体   English

访问所选Kendo TreeView节点的子节点

[英]Accessing the Child Nodes of a Selected Kendo TreeView Node

I have an Ajax populated treeview.... 我有一个Ajax填充树视图....

@(Html.Kendo().TreeView()
    .Name("fao")
    .HtmlAttributes(new {@class="fixed-height" })
    .DataTextField("Text")
    .TemplateId("treeview-item-template")
    .DataSource(ds => ds
        .Read(r => r
            .Action("_ModuleData", "Home")
        )
        .Model(m => m
            .Children("Items")
            .HasChildren("HasChildren")
        )
    )
)

I have a requirement to update some data hidden against each child item - in the template - when a action (triggered outside of the control) occurs. 我需要更新一些隐藏在每个子项目中的数据 - 在模板中 - 当一个动作(在控件之外触发)发生时。

The template, for completeness, looks like this ... 完整性模板看起来像这样......

<script id="treeview-item-template" type="text/kendo-ui-template">
    #= item.Text #<input type='hidden' class='hidden-data' data-fal='#= item.Fal#' data-uid='#=item.uid#'/>
</script>

Now, I have code for the trigger and that works just fine. 现在,我有触发器的代码,并且工作得很好。

I have code to update the hidden data. 我有代码来更新隐藏数据。 Again. 再次。 No worries. 别担心。

What I can't figure out is how to simply get at all of the child (and granchild, etc) nodes of the node that is selected when the trigger fires. 我无法弄清楚的是如何简单地获取触发器触发时所选节点的所有子节点(和granchild等)节点。

If I were trying to get at the children when the node was initially clicked, I kind of expected to be able to say something like... 如果我在最初点击节点时试图找到孩子们,我希望能够说出类似...

function doSomething(e)
{
    for(n=0; n<e.node.nodes.length; n++)
    {
        doSomethingElse(e.node.nodes[n]);
    }
}

But no such functionality seems to exist. 但似乎不存在这样的功能。

Does anyone have any suggestions how I might go about this? 有没有人有任何建议我怎么可能这样做?

You can access the children via the model which you can get from the DOM node: 您可以通过您可以从DOM节点获取的模型访问子项:

var dataItem = e.sender.dataItem(e.node);
if (dataItem.hasChildren) {
    var children = dataItem.children.data();
}

This will only get you direct children, so you'd have to make it recursive to get all descendants. 这只会让你直接生孩子,所以你必须让它递归才能得到所有的后代。

( demo ) 演示

OK. 好。

It seems I can get at all of the nodes on the TreeView like this ... 看来我可以像这样得到TreeView上的所有节点......

var allNodes = $(".k-item");

Likewise, I can get at all of the child nodes of a given node like this ... 同样,我可以像这样得到给定节点的所有子节点......

// node is the node under which we need all of the child nodes
var childNodes = $(".k-item", node);

And, for any given node, I can get the dataItem like this ... 并且,对于任何给定的节点,我可以像这样得到dataItem ......

var dataItem = tree.dataItem(node);

I believe that all of the above only holds if the data for all of the child nodes below the selected node have been loaded. 我相信,如果已加载所选节点下的所有子节点的数据,则上述所有内容都成立。 In my case, I'm loading from remote data (using AJAX) but I have .LoadOnDemand(false) in the definition of my grid. 在我的情况下,我从远程数据(使用AJAX)加载,但我的网格定义中有.LoadOnDemand(false)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Telerik Kendo TreeView中删除所选节点的子节点 - How can I delete child nodes of selected node in telerik kendo treeview Kendo Treeview-如何在另一个Treeview中显示具有所有父节点的选定节点 - Kendo Treeview - How to Display selected node with all parent nodes in another treeview Kendo TreeView 移动父节点以更改排序顺序但不允许将父节点拖到子节点下 - Kendo TreeView Move Parent nodes to change the Sort Order but not allow a Parent to be dragged under a Child node Kendo UI TreeView-单击已选择的节点 - Kendo UI TreeView - click on an already selected node Kendo Treeview 复选框与所选节点一起选中 - Kendo Treeview checkbox checked together with selected node Kendo TreeView默认选定的节点不会触发onSelect - Kendo TreeView default selected node doesn't trigger onSelect 访问父节点的子节点的XML与某些子节点只 - accessing child node of parent nodes in xml with certain child nodes only 选择根节点时的 Select 子节点 - Select child nodes when root node is selected 当父节点被选中时,如何触发Kendo TreeView中子节点的onCheck事件 - How to trigger the onCheck event for child nodes in Kendo TreeView, when parent is checked 如果选择了所有子节点,如何将父树节点标记为选中 - How to mark parent tree node as selected if all the child nodes are selected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM