But I need to get all nodes from WebDataTree by js
How I can get all nodes from WebDataTree by js?
Hello Anton Pridanov,
Thank you for posting in the community!
The count of all nodes in WebDataTree should be accesible by iterating through all the parent nodes and taking their children, for instance:
function loopThroughNodes() { var tree = $find("<%= webdatatree1="" clientid="">"); for(var i = 0; i < tree.getNodes().get_length(); i++) { var rootNode = tree.getNodes().getNode(i); recursiveIteration(rootNode); } } function recursiveIteration(node) { console.log(node.get_text()); if(node.hasChildren()) { for(var j = 0; j < node.getItems.get_lenght(); j++) { var child = node.getItems().getNode(j); recursiveIteration(child); } } }
function loopThroughNodes() {
var tree = $find("<%= webdatatree1="" clientid="">");
for(var i = 0; i < tree.getNodes().get_length(); i++) {
var rootNode = tree.getNodes().getNode(i);
recursiveIteration(rootNode);
}
function recursiveIteration(node) {
console.log(node.get_text());
if(node.hasChildren()) {
for(var j = 0; j < node.getItems.get_lenght(); j++) {
var child = node.getItems().getNode(j);
recursiveIteration(child);
I am also attaching a sample for your scenario using version 12.2.20122.2031 for you.
Do not hesitate to contact me if you need any further support.
Edit:Code Review
Do not hesitate to contact me if you have any additional questions concerning this matter.
This solution dont work for such structure:
RootNode
-node1
--node11
---node111
-node12
--node121
-node2
-node3
when we get to the ---node111 it became infinite loop
Thanks, for you reply. We solve the problem.
Hello Anton,
I am still following your case. Have been able to resolve your issue?
If you still have any concerns or questions I would be glad to help.If you need any additional assistance do not hesitate to ask.
The iterators for the for loops had to be defined as variables in this case to ensure correct scoping. Here is the revised function:
function loopThroughNodes() { var tree = $find("<%= WebDataTree1.ClientID %>"); for (var i = 0; i < tree.getNodes().get_length(); i++) { var rootNode = tree.getNodes().getNode(i); recrusiveIteration(rootNode); } } function recrusiveIteration(node) { console.log(node.get_text()); if (node.hasChildren()) { for (var j = 0; j < node.getItems().get_length(); j++) { var child = node.getItems().getNode(j); recrusiveIteration(child); } } return; }
var tree = $find("<%= WebDataTree1.ClientID %>");
for (var i = 0; i < tree.getNodes().get_length(); i++) {
recrusiveIteration(rootNode);
function recrusiveIteration(node) {
if (node.hasChildren()) { for (var j = 0; j < node.getItems().get_length(); j++) {
recrusiveIteration(child);
return;
Feel free to contact me if you have ant further questions.