This is a migrated thread and some comments may be shown as answers.

Kendo UI Treeview Checked - Get text of all selected nodes?

2 Answers 820 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Hardeep
Top achievements
Rank 1
Hardeep asked on 07 Oct 2013, 12:45 PM
Hi,
I need text of all selected nodes in the Treeview (Checked) in an array.

I can traverse through the selected nodes but not able to read text. text property not working

$("#treeview .k-item input[type=checkbox]:checked").closest(".k-item").each(function () {
// change whatever you want, for example:
**alert($(this).data.text);**
$(this).css("color", "green");
});


Thank You.
Best Regards.

2 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 09 Oct 2013, 08:14 AM
Hi Hardeep,

In order to use the text() method you should get a reference to the TreeView widget (this in the provided code snippet are actually the treeView items). Please try the following: 

//get reference to the TreeView widget
var treeview = $("#treeview").data("kendoTreeView");
//get the checked items
var items = $("#treeview .k-item input[type=checkbox]:checked").closest(".k-item");
//console.log the text for each item
$(items).each(function(){console.log(treeview.text(this))});
Regards,
Iliana Nikolova
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Hardeep
Top achievements
Rank 1
answered on 09 Oct 2013, 08:27 AM
Thanks Iliana           
I will check the code suggested by you.

Below code working fine for me

 var checkedNodesStation = [];
 $("#treeviewStation .k-item input[type=checkbox]:checked").closest(".k-item").each(function () {
checkedNodesStation.push(this.textContent);
});


Thanks.
Hardeep


Tags
TreeView
Asked by
Hardeep
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Hardeep
Top achievements
Rank 1
Share this question
or