我是Angulrajs的新手,我想在html页面中列出JSON对象。我想我必须递归地进入对象。 Angularjs有什么可以做的事吗?递归调用Angularjs
我有嵌套的对象。所以,我必须进入这一点。
我是Angulrajs的新手,我想在html页面中列出JSON对象。我想我必须递归地进入对象。 Angularjs有什么可以做的事吗?递归调用Angularjs
我有嵌套的对象。所以,我必须进入这一点。
您将使用ng-repeat来循环您的对象。喜欢这个。
<ul>
<li ng-repeat="stuff in things"> stuff </li>
</ul>
*编辑后。你认为你必须使用递归,因为你有嵌套的对象。这并非完全正确。你可以使用多个ng-repeats。像这样的东西。
<div>
<div ng-repeat="stuff in things">
<span> stuff </span>
<div ng-repeat="morestuff in stuff">
moreStuff
</div>
</div>
'ng-repeat'不提供递归,只有迭代。 –
是的,这引出了为什么需要递归的问题。我打赌它不是这种情况。 –
好吧,你可以在评论中询问它,而不是猜测(即使OP已经明确表示他会*“必须递归进入对象”*)。 –
如果你还在寻找真正的递归,这里是你能做什么(例如,递归嵌套评论)
<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>
只使用递归,你通常会在JavaScript。 –