简体   繁体   English

在树形视图中选择父级时如何获取子级名称

[英]how to get the child names when i select the parent in the tree view

I am using kendoUI tree view with check boxes implementation. 我正在使用带有复选框实现的kendoUI树形视图。 I am able to check all children's check boxes,when i select the parent checkbox. 当我选择父复选框时,我能够选中所有儿童的复选框。 now,I want to get all the children's text values when i select the parent check box. 现在,我想在选中父复选框时获得所有孩子的文本值。 I used template for check box operation in tree view 我在树状视图中使用模板进行复选框操作

$("#ProjectUsersTreeView [type=checkbox]").live('change', function (e) {                       var chkbox = $(this);
                        var parent = chkbox.parent();                            
    var pBox = $(parent).closest('.k-item').find(":checkbox");                               

                       if (this.checked || pBox.length>0) {
                           $(pBox).prop('checked',this.checked ? "checked": "")      
}

Instead of using your code for checking children I do recommend using KendoUI configuration option checkChildren. 建议不要使用KendoUI配置选项checkChildren,而不要使用代码来检查孩子。

tree = $("#ProjectUsersTreeView").kendoTreeView({
            checkboxes:{
                checkChildren: true
            },
            ...
        }).data("kendoTreeView");

Then for getting all selected text use: 然后,要获取所有选定的文本,请使用:

$("#ProjectUsersTreeView [type=checkbox]").live('change', function (e) {
            var checked = $("input:checked", tree);
            $.each(checked, function(idx, elem) {
                console.log("text", tree.text(elem));
            })
        });

In checked I get all input elements from the tree that are actually checked and display its text on console by getting it using text method. checked我从树中获取了所有实际checked input元素,并通过使用text方法获取它在控制台上显示其文本。

NOTE : Realize that I've defined tree as $("#ProjectUsersTreeView").data("kendoTreeView") and then use it in change handler. 注意 :意识到我已经将tree定义为$("#ProjectUsersTreeView").data("kendoTreeView") ,然后在change处理程序中使用它。

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

相关问题 如何将用户限制为 select 只有一个来自父节点 Kendo Tree 视图 MVC 的子节点 - How to restrict user to select only one child from parent node Kendo Tree view MVC 如何使用asp.net获取树视图中父节点的最后一个子节点? - how to get the last child of the parent node in Tree View using asp.net? 当父视图具有相同模型时,如何将局部视图中的 HTML 表单数据序列化? - How do I get HTML form data in Partial View to be serialized when parent view has same model? 如何将父子表传递给我的视图 - How pass a parent child table to my view 如何在父视图中添加或编辑孩子 - How to add or edit a child in parent view 当我们单击子复选框时,如何获取父母的父母ID - How to get the parent id of the parent when we click on the child check box 如何将子局部视图添加到父局部视图? - How to add child partial view to parent partial view? 当页面首次加载到父视图中时,如何从局部视图中获取第一行“名称”的值? - How to get the value of 1st row “Name” from partial view when page first loads in parent view? 创建子对象时如何从子对象内的父对象获取ID? (MVC) - How to get ID from parent object inside child object when creating it? (MVC) 在读取视图数据时如何添加选择参数? - How do I add select parameters when reading data for the View?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM