dynatree: selecting child nodes programmably

1,942 views
Skip to first unread message

Muhammad Adeel Zahid

unread,
May 13, 2010, 9:11:24 AM5/13/10
to Discuss jquery.dynatree.js
hello everyone

i m using jquery's dynaTree in my application and i want to select the
all the child nodes programmably when a node is selected. the
structure of my tree is as follows

<div id = "tree">
<ul>
<li>package 1
<ul>
<li>module 1.1
<ul>
<li> document 1.1.1</li>
<li> document 1.1.2</li>
</ul>
</li>
<li>module 1.2
<ul>
<li>document 1.2.1</li>
<li>document 1.2.2</li>
</ul>
</li>
</ul>
</li>
<li> package 2
<ul>
<li> module 2.1
<ul>
<li>document 2.1.1</li>
<li>document 2.1.1</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

now what i want is that when i click on tree node with title "package
1" all its child nodes i.e (module 1.1, document 1.1.1, document
1.1.2, module 1.2, document 1.2.1, document 1.2.2) should also be
selected

below is the approach i tried to use


$("#tree").dynatree({
onSelect: function(flag, dtnode) {
// This will happen each time a check box is selected/
deselected
var selectedNodes = dtnode.tree.getSelectedNodes();
var selectedKeys = $.map(selectedNodes, function(node) {

//alert(node.data.key);
return node.data.key;


});
// Set the hidden input field's value to the selected
items
$('#SelectedItems').val(selectedKeys.join(","));

if (flag) {
child = dtnode.childList;

alert(child.length);
for (i = 0; i < child.length; i++) {
var x = child[i].select(true);
alert(i);
}
}
},
checkbox: true,
onActivate: function(dtnode) {
//alert("You activated " + dtnode.data.key);
}


});

in the if(flag) condition i get all the child nodes of element that is
selected by user and it gives me the correct value that i can see from
alert(child.length) statement. then i run the loop to select all the
children but loop never goes beyond the statement

var x = child[i].select(true);

and i can never see the statement alert(i) being executed. the result
of above statement is that if i select package 1, module 1.1 and
document 1.1.1 is also selected but never does it execute alert(i)
statement neither other children of package 1 are selected. in my view
when first time child[i].select(true) statement is executed it also
triggers the on select event of its children thus making a recursion
kind of thing
is my thinking correct?
no matter recursion or what why on earth does it not complete the loop
and execute very next instruction alert(i).
please help me in solving this problem. i m dying to see that alert
any suggestion and help is highly appriciated
thanks
Adeel

--
You received this message because you are subscribed to the Google
Groups "Discuss jquery.dynatree.js" group.
To post to this group, send email to dyna...@googlegroups.com
To unsubscribe from this group, send email to
dynatree+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dynatree?hl=en
Message has been deleted

mar10

unread,
May 16, 2010, 6:32:00 AM5/16/10
to Discuss jquery.dynatree.js
Reply all
Reply to author
Forward
0 new messages