Javascript 如何使用ngFor循环遍历Angular中未知数量的嵌套json对象?
我正在尝试显示来自此json的所有回复: 因此,根据即时通讯后的加载和回复,我的孩子数量会有所不同。如何循环遍历它,直到到达最后一个带有子对象的回复(body[2].data.children) 像这样:Javascript 如何使用ngFor循环遍历Angular中未知数量的嵌套json对象?,javascript,json,angular,Javascript,Json,Angular,我正在尝试显示来自此json的所有回复: 因此,根据即时通讯后的加载和回复,我的孩子数量会有所不同。如何循环遍历它,直到到达最后一个带有子对象的回复(body[2].data.children) 像这样: <div class="replies-box" *ngFor="let reply of comments.body[1].data.children"> <div class="reply-header&q
<div class="replies-box" *ngFor="let reply of comments.body[1].data.children">
<div class="reply-header">
<p class="reply-author"><b>From</b> : {{ reply.data.author }}</p>
<p class="reply-send"><b>Send</b> : {{ this.getDateReply(reply.data.created_utc) }}</p>
</div>
<div class="text-first-reply" [innerHTML]="this.getHtmlDecode(reply.data.body_html)">
</div>
</div>
发件人:{reply.data.author}
send:{{this.getDateReply(reply.data.created_utc)}
我只有第一个层次的回答,有没有办法简单地对它们进行循环?
提前感谢。在ng容器的帮助下,只需在ngFor内部使用ngFor(不会创建额外的dom元素)
发件人:{reply.data.author}
发送:{{this.getDateReply(reply.data.created_utc)}
我将使用递归类型的方法
开发一个appcomment
组件,如果comment有子项,则循环子项并显示appcomment
。这样,它将在注释上循环,直到没有更多的子项为止
种类:{{comment.Kind}
{{comment}}
这太完美了,正是我所需要的,非常感谢!