2012-11-24 134 views
0

我想以编程方式创建新节点。 然后我想在另一个节点之前添加它作为兄弟。创建一个节点并将其作为兄弟节点添加到另一个与dynatree的兄弟之前

此代码不起作用:

var node = $("#TreeDiv").dynatree("getActiveNode"); 
var nextSiblingNode = node.getNextSibling(); 
var childNode = node.addChild({ title: response.title, key: response.unitId }, nextSiblingNode); 

什么我错了吗?

UPDATE:

,这是我与上面的代码得到了异常:

Unhandled exception at line 4, column 20662 in http://localhost:1726/Scripts/jquery.dynatree.min.js 

0x800a139e - runtime error in JavaScript: <beforeNode> must be a child of <this> 
+0

你得到什么错误信息? – ajtrichards

+0

我用错误消息更新了我的问题。 – Elisabeth

+0

@ socialrel8关于错误消息的任何想法? – Elisabeth

回答

1

创建该节点作为一个孩子,我不得不搬到节点后和它的工作......当然的代码仍然需要一些空的检查;-)

var newNode = { title: response.title, key: response.unitId }; 
var activeNode = $("#TreeDiv").dynatree("getActiveNode"); 
var nextSiblingNode = activeNode.getNextSibling(); 
if (nextSiblingNode != null) { 
    newNode = activeNode.addChild(newNode); 
    newNode.move(nextSiblingNode, 'before'); 
} 
else 
{      
    var parentNode = activeNode.getParent(); 
    newNode = parentNode.addChild(newNode); 
} 
newNode.activate(true); 
newNode.focus(true); 
相关问题