DynaTree根节点null / undefined - 未定义的子节点

时间:2010-12-30 15:53:19

标签: javascript jquery dynatree jquery-dynatree

("#tree").dynatree({                
minExpandLevel: 1,              
//persist: true,                
children: [{"title":"First Location",
"isFolder":true,
"expand":true,
"key":"location.92",
"icon":"location.gif",
"children":[{"title":"<span class='assetType'>First Location Child<\/span>",
"key":"locationid=92&typeid=1",
"expand":true,
"icon":"equipment.gif",
"children":[ (etc...)

所以我这样做:

var rootNode = $("#tree").dynatree("getRoot");
var title = rootNode.data.title;

title = null

...好的,我试试:

var rootNode = $("#tree").dynatree("getRoot");
var node = rootNode.getChildren();
var title = node.data.title;

无法读取未定义的属性'title'

如果我只是:

alert(node);

我明白了:

DynaTreeNode&lt; location.92&gt;:'First Location'

所以...?

因为我在控制台问:

jquery.dynatree.min.js:710:49:53.215 - Option 'title' is no longer supported.

相关?

Uncaught TypeError: Cannot read property 'parentNode' of null
ra

3 个答案:

答案 0 :(得分:5)

rootNode是(不可见)系统根,未设置rootNode.data.title。 由于node.getChildren()返回一个列表,因此它应该是

var rootNode = $("#tree").dynatree("getRoot");
var nodeList = rootNode.getChildren();
var title = nodeList[0].data.title;

答案 1 :(得分:2)

我得到了答案:

//node = item which has isFolder() = false, islazy() = false

var topnode = node.parent;
topnode.reloadChildren(function(topnode, isOk){});

答案 2 :(得分:0)

您可以使用以下方式阅读标题:

var rootNode = $("#tree").dynatree("getRoot");  
var realRootTitle = rootNode.childList[1].data.title;