Javascript Angularjs中的递归调用
我是Angulrajs的新手,我想在html页面中列出一个JSON对象。我想我必须递归地进入这个对象。在Angularjs中有什么可以做的吗 我有嵌套对象。所以,我得谈谈这个问题 您将使用它在对象上循环。像这样Javascript Angularjs中的递归调用,javascript,angularjs,recursion,Javascript,Angularjs,Recursion,我是Angulrajs的新手,我想在html页面中列出一个JSON对象。我想我必须递归地进入这个对象。在Angularjs中有什么可以做的吗 我有嵌套对象。所以,我得谈谈这个问题 您将使用它在对象上循环。像这样 <ul> <li ng-repeat="stuff in things"> stuff </li> </ul> 东西 *编辑之后。您认为必须使用递归,因为您有嵌套对象。这并不完全正确。您可以使用多个ng重复。像这样的 <
<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>
东西
更多
如果您仍在寻找真正的递归,下面是您可以做的事情(例如,递归嵌套注释)
{{comment.author}}
{{comment.text}
创建:{{comment.Created_at}},
上次编辑:{{comment.updated_at}
就像在javascript中一样使用递归。ng repeat
不提供递归,只提供迭代。是的,这就提出了为什么需要递归的问题。我敢打赌不是在这种情况下。好吧,你可以在评论中询问,而不是猜测(即使OP明确表示他将“必须递归地进入对象”)。让我们继续,不要挑选他说的话。我相信他说的是‘我想我必须递归地进入对象’。这么大的“我想”是我发布答案的原因。很可能我错了,但如果我是对的,ng repeat将为他节省大量的时间。我也能看出你是从哪里来的。感谢您的退出,祝您度过一个愉快的夜晚或一天:)
<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>