2014-05-19 5 views

답변

1

내가 본 것으로부터, 현재 선택된 노드의 ID를 얻을 수 있습니다.이 노드는 이미 부모 ID의 연결입니다.

  1. 이 (각각의 TreeNode에 부모의 속성을 추가

    모든 부모 ID를 가진 배열을 원하는 경우에, 당신은 다음과 같은 작업을 수행 할 수

    <div data-bind="with: selected"> 
        Selected Node:     <span data-bind="text: name"></span> 
        </div> 
    

    <div data-bind="with: selected"> 
        Selected Node:     <span data-bind="text: name"></span> 
        Ids: <span data-bind="text: id"></span> 
        </div> 
    

    으로 교체 parent) 생성자에 채우기

  2. 모두의 TreeNode를 통해 이동하고 parentIds 배열

확인이 코드 (1 기입하는 함수를 작성 부모 식별자 (parentIds)

  • 의 배열을 추가합니다.

    function TreeNode(values) { 
         var self = this; 
         ko.mapping.fromJS(values, { children: { create: createNode }}, this); 
         this.expanded = ko.observable(false); 
         for (var i = 0; i < this.children().length; i++) 
          this.children()[i].parent = this; 
         this.parentIds = []; 
         this.collapsed = ko.computed(function() { 
         return !self.expanded(); 
        }) 
        } 
    

    그리고이 (3) : & 2) 당신은 응답을 here

  • +0

    감사를 확인할 수 있습니다

    function setParents(rootNode) { if (ko.isObservable(rootNode.children) && rootNode.children().length) for (var i = 0; i < rootNode.children().length; i++) { if (rootNode.children()[i].parent) rootNode.children()[i].parentIds = rootNode.children()[i].parent.parentIds.slice(0); rootNode.children()[i].parentIds.push(rootNode.children()[i].parent.id()) setParents(rootNode.children()[i]); } } setParents(root); 

    , 내가 모든 부모 노드 ID를 원했다. 이 경우 ID가 "1.1.2"인 노드를 클릭하면 >> 결과는 다음과 같습니다. 1 >> 1.1 >> 1.1.2 –

    +0

    역순으로 트래버스하고 모든 선택한 항목의 상위 ID입니까? –

    +0

    나는 –

    관련 문제