2012-10-17 2 views
0

내 프로젝트에서 지연로드와 함께 dynatree를 사용하려고했습니다. 선택 기능과 확인란을 결합하여 모드 3을 선택하려고 시도했을 때 모드 3에 대한 선택 규칙은 부모를 선택하면 자녀를 포함한 모든 항목을 선택하는 것을 보게되어 실망했습니다. 어린이들이 아직 출근하지 않았기 때문입니다.지연로드를 사용할 때 dynatree selectmode = 3이 적용되지 않습니다.

아무에게도 해결 방법이 있습니까? 어떤 제안이라도 대단히 감사 할 것입니다. Zank 나중에!

답변

0

선택한 부모의 하위 항목을 추가 할 때 상위 항목에 하위 항목이 있는지 확인하십시오. 참이면 각 하위를 추가하고 각 하위를 선택하도록 설정합니다.

다음은 몇 가지 코드입니다. 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}); 
    } 
0

시피 다음 해킹의 비트이다 .. 그러나이 문제를 해결한다 : 노드가되는 경우

onSelect: function (flag, node) { 
    if (flag && node.childList == undefined) { 
     node.reloadChildren(function() { 
      node.select(false); 
      node.select(true); 
     }); 
    } 

을 selected (flag == true) 노드가 아직로드되지 않았고 (childList == undefined) 다음 콜백 함수로 reloadChildren을 호출합니다. 콜백은 데이터가로드 된 후에 실행되며 단순히 체크 박스를 선택/해제합니다. 이렇게하면 현재 존재하는 모든 하위 노드가 선택됩니다.

관련 문제