ディレクティブ<ul />
を使用して見られる典型的な入れ子構造とは異なる、水平バイナリ ツリー構造を作成する必要があります。ng-repeat
ng-include を使用して、ネストされたオブジェクトを渡すか、必要なネストされたオブジェクトを取得するにはどうすればよいですか?
コードは次のとおりです。
<div id="tree-container" ng-controller="CommentController">
<ul class="root-tree" id="current-tree">
<li class="root node">
<div class="feed">
<div class="comment">{{data.comment}}</div>
</div>
</li>
<li class="root-children">
<ul class="tree" ng-include="'tree'"></ul>
</li>
</ul>
</div>
<script>
app.controller("CommentController", ["$scope", function ($scope) {
$scope.data = {
comments: "blah",
leftChildren: {
comments: ["blah", "blah", "blah"],
leftChildren: { comments: ["blah", "blah", "blah"] },
rightChildren: { comments: ["blah", "blah", "blah"] }
},
rightChildren: { comments: ["blah", "blah", "blah"] }
};
)]);
</script>
<script type="text/ng-template" id="tree">
<li class="node">
<div class="feed">
<div class="comment" ng-repeat="comment in data.leftChildren">{{comment.comment}}</div>
</div>
</li>
<li class="node">
<div class="feed">
<div class="comment" ng-repeat="comment in data.rightChildren">{{comment.comment}}</div>
</div>
</li>
<li class="left-children">
<ul class="tree" ng-include="'tree'"></ul>
</li>
<li class="right-children">
<ul class="tree" ng-include="'tree'"></ul>
</li>
</script>
#tree
テンプレートには、2 つのng-include
ディレクティブがあることがわかります。$scope
入れ子ng-include
になった for each で、階層の次のレベルを on で使用したいと思います。$scope.data
これはleftChildren
andになりrightChildren
ます。
言い換えれば、私は基本的ng-repeat
に、ネストされた配列を呼び出すときと同じ効果が欲しい$scope
.
うまくいけば、これはすべて理にかなっています:)