ngFor를 사용하여 Angular에서 중첩 된 json 객체의 알 수없는 수를 반복하는 방법은 무엇입니까?

Chabou bou

이 json의 모든 응답을 표시하려고합니다.

https://www.reddit.com/r/AskReddit/comments/k8w43d/people_with_the_last_name_pepper_who_have.json

그래서 포스트 메신저 로딩과 답장에 따라 아이들의 수가 달라집니다. 아이들 (body [2] .data.children)과 함께 마지막 응답에 도달 할 때까지 어떻게 반복 할 수 있습니까?

이렇게 :

<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>

첫 번째 수준의 회신 만 있습니다. 모두를 반복하는 방법이 있습니까? 미리 감사드립니다.

오웬 켈빈

재귀 유형의 접근 방식을 사용합니다.

app-comment구성 요소를 개발하고 주석에 자식이 있으면 자식을 반복하고 app-comment. 이렇게하면 더 이상 자식이 없을 때까지 주석을 반복합니다.

<div *ngIf='comment'>
  <span *ngIf='comment.kind; else showComment'>Kind: {{ comment.kind }}</span>
  <ng-template #showComment>
    <span>{{ comment }}</span>
  </ng-template>
  <div>
   <app-comment *ngFor='let child of comment.data?.children' [comment]='child'> </app-comment>
  </div>
</div>

이 샘플 그림보기

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관