[英]How to restrict user to select only one child from parent node Kendo Tree view MVC
[英]how to get the child names when i select the parent in the tree view
我正在使用帶有復選框實現的kendoUI樹形視圖。 當我選擇父復選框時,我能夠選中所有兒童的復選框。 現在,我想在選中父復選框時獲得所有孩子的文本值。 我在樹狀視圖中使用模板進行復選框操作
$("#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": "")
}
建議不要使用KendoUI配置選項checkChildren,而不要使用代碼來檢查孩子。
tree = $("#ProjectUsersTreeView").kendoTreeView({
checkboxes:{
checkChildren: true
},
...
}).data("kendoTreeView");
然后,要獲取所有選定的文本,請使用:
$("#ProjectUsersTreeView [type=checkbox]").live('change', function (e) {
var checked = $("input:checked", tree);
$.each(checked, function(idx, elem) {
console.log("text", tree.text(elem));
})
});
在checked
我從樹中獲取了所有實際checked
input
元素,並通過使用text
方法獲取它在控制台上顯示其文本。
注意 :意識到我已經將tree
定義為$("#ProjectUsersTreeView").data("kendoTreeView")
,然后在change
處理程序中使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.