1

I'm a new user of dynatree plugin. When I read the documentation, I found the list of tree and node class member functions, such as tree.getRoot(), node.countChildren(). However, when I tried to use them, it complained that no such methods were found. Here is a sample code I am testing with:

var tree = ("#test").dynatree(treeData);
var rootNode = tree.getRoot(); //not working
var rootNode2 = ("#test").dynatree("getRoot"); //this works
var numChildren = rootNode2.countChildren(); //not working

Help please. Thanks. -JJ

Jj Zhang
  • 11
  • 2

2 Answers2

0

Are you missing the leading $?

Valid samples are:

var rootNode = $("#tree").dynatree("getRoot");
var tree = $("#tree").dynatree("getTree");
var node = $("#tree").dynatree("getActiveNode");
node.setTitle(node.data.title + ", " + new Date());

See here for samples (click View source code): http://wwwendt.de/tech/dynatree/doc/sample-api.html

mar10
  • 14,320
  • 5
  • 39
  • 64
0
var tree = $("#test").dynatree(treeData);

Your first line gives you the #test html element.

In order to obtain the tree object try:

var tree = $("#test").dynatree(treeData).dynatree("getTree");

Now these lines will work:

var rootNode = tree.getRoot();
var numChildren = rootNode.countChildren();