2016-12-15 35 views
0

我在春天引導和角JS應用程序的工作生成樹使用jhipster創建的,在此我有生成樹狀視圖像長數據

    • Child_1
    • Child_2
      • Sub_Child_2_1
        • Sub_Child_2_1_1
    • Child_3
      • Sub_Child_3_1
    • Child_4
    • Child_5
      • Sub_Child_5_1
      • Sub_Child_5_2
      • Sub_Child_5_3 ...... ...... ......

在初始水平,我將加載的孩子與兩個層次,即根 - > Child_1..2..3 .. 後面的sub_child會按照需求加載。樹的深度不固定,可能會有所不同。數據非常大。所以我不能在初始階段加載所有內容。

我希望樹被展開和摺疊功能。

編輯:我曾嘗試ABN樹,但它造成的問題中提到:abn tree fail to show correctly when reach to level 9

什麼將是最好的解決方案,我jhipster應用程序中創建樹,以便它可以很容易地編輯?

回答

0

您可以在這裏創建自定義指令來爲您的數據生成樹結構。

+0

謝謝,你能告訴我榜樣,也已經更新了這個問題。 –

+0

你能請嘗試以下鏈路 http://angular-js.in/angular-tree-control/ http://alexsuleap.github.io/ http://angularscript.com/demo/Creating-a-tree-structure-with-angularjs-and-json-data-angularjs-tree/ – Prasad

0

實際上,你可以使用模板:

樹JSON:

$scope.tree = [ 
    { 
     name: "Child 1" 
    }, 
    { 
     name: "Child 2", 
     subs: [ 
      { 
       name: "Subchild 2 1", 
       subs: [ 
        { 
         name: "Subchild 2 1 1" 
        } 
       ] 
      } 
     ] 
    } 
]; 

HTML:

<script type="text/ng-template" id="myTemplate"> 
    <ul> 
     <li ng-repeat="item in childs"> 
      {{ item.name }} 
      <div ng-include="'myTemplate'" 
       ng-if="item.subs" 
       ng-init="childs = item.subs"></div> 
     </li> 
    </ul> 
</script> 

<div ng-include="'myTemplate'" ng-init="childs = tree"></div> 
+0

謝謝,請參閱更新後的問題。 –