我是Angulrajs的新手,我想在html页面中列出一个JSON对象。我想我必须递归地进入对象。是否可以在Angularjs中完成任何事情。
我有嵌套对象。所以,我必须进入那个。
答案 0 :(得分:2)
您将使用ng-repeat循环对象。像这样。
<ul>
<li ng-repeat="stuff in things"> stuff </li>
</ul>
编辑后*。您认为必须使用递归,因为您有嵌套对象。这不完全正确。您可以使用多个ng重复。这样的事情。
<div>
<div ng-repeat="stuff in things">
<span> stuff </span>
<div ng-repeat="morestuff in stuff">
moreStuff
</div>
</div>
答案 1 :(得分:1)
如果您仍在寻找真正的递归,那么您可以做什么(例如,递归嵌套注释)
<div class="panel panel-default"
ng-repeat="comment in comments"
ng-include="'comment_recursion.html'">
</div>
<!-- == Recursion script == -->
<script type="text/ng-template" id="comment_recursion.html">
<div ng-controller="CommentCtrl">
<div class="panel-heading">
{{comment.author}}
<%= render "layouts/controverse_btns" %>
</div>
<div class="panel-body">
{{comment.text}}
</div>
<div class="panel-footer">
<span>Created :{{comment.created_at}}, </span>
<span>Last Edited : {{comment.updated_at}}</span>
</div>
</div>
<!-- Comment replies (other comments), might want to indent to the right -->
<div class="reply" ng-if="comment.replies">
<div class="panel panel-default"
ng-repeat="comment in comment.replies"
ng-include="'comment_recursion.html'">
</div>
</div>
</script>