[英]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.