선택한 부모의 하위 항목을 추가 할 때 상위 항목에 하위 항목이 있는지 확인하십시오. 참이면 각 하위를 추가하고 각 하위를 선택하도록 설정합니다.
다음은 몇 가지 코드입니다. onLazyRead
이 맨 위로 올라갈 것입니다. 게으른 노드를 클릭 할 때마다이 함수가 트리거됩니다. 이 함수 안에는 방금 선택한 노드에 대한 자식 데이터를 가져 오는 함수를 호출해야합니다.
아래 코드는이 문제를 해결 한 방법입니다. 거의 모든 일은 당신이 추가하고있는 노드의 부모가 선택되었는지 확인하는 것입니다. 참인 경우 노드를 추가 한 다음 .select()
노드를 추가합니다.
모든 노드가 이미로드되어 있기 때문에 노드 선택을 취소하면 훨씬 간단 해집니다. 선택을 해제 할 때 선택 해제되는 노드에서 트리의 계층 구조로 내려 가서 각 노드의 선택을 취소하면됩니다.
나는 이것이 당신에게 던질 코드가 많다는 것을 알고 있지만 잘하면 그 아이디어를 파악할 수있다. 당신이 할 수 없다면, 나는 일하는 동안이 글을 다시 확인하려고 노력할 것이다. 어쩌면 당신은 지금까지 가지고있는 것을 게시 할 수 있습니까?
onLazyRead: function(node){
jQuery("#tree2").dynatree("getTree").disable();
var pParentID = node.data.key;
//Select the Node
doChildReport(pParentID); //Get Children for this node's ID
},
///....
//Methods to grab data from a "XMLHttpRequest GET" go here
//....
//When you finally want to add the children that you fetched using the ID of the node you selected...
//treeArray is an array of node data that has been parsed out of a
//string returned by a "XMLHttpRequest GET"
//Contents of array in order, repeating: treeArray[0] = ParentID, [1] = nodeID [2] = nodeName
//Example, the array would return [111], [222], ["Child Node"]
if(){ //IF Next fetched node is on the last level, ie. no children
//add normally
}
else{ //If NOT, add lazy.
if(treeArray[1] != "nill" && treeArray[1] != undefined){
//IF THE PARENT NODE IS SELECTED
if(jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[0]).isSelected() == true){
//AND IF the child node does not exist
if(jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[1]) == null){
//Add the child node and then mark it selected
addChildNodeLazy(treeArray[1], treeArray[2], treeArray[0]);
jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[1]).select();
}
}else{
if(jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[1]) == null){
addChildNodeLazy(treeArray[1], treeArray[2], treeArray[0]);
}
}
}
}
레이지로드 기능 ...
function addChildNodeLazy(NodeID, NodeName, ParentID){
jQuery("#tree2").dynatree("getTree").getNodeByKey(ParentID).addChild({title: NodeName, key: NodeID, icon: false, isFolder: true, isLazy: true});
}