简体   繁体   中英

Print Json Nested Array in Array all elements

JSON DATA Format I have Json file nested data the data is inside the array in array and some array have inside 2 array and some have 4 and some folders don't have ant array . I want print all array data if inside 2,3,4 and nested 2 or 4 .

I print the 3 array data in angular using the for loop inside the loop .i use 3 for loop and 3 times data print

 <ul *ngFor="let bird of parts_">
     <li>{{bird.name}}</li>
     <li [ngStyle]="{'color': bird.type == 'folder' ? 'red' : 'green'}"> 
        {{bird.type}}</li>
     <ul *ngFor="let item of bird.items">
       <li>{{item.name}}</li>
       <li >
       <ul *ngFor="let item1 of item.items">
         <li>{{item1.name}}</li>

         <ul *ngFor="let item2 of item1.items">
           <li>{{item2.name}}</li>
         </ul>
       </ul>
      </li>
     </ul>

</ul> 

3 Time Loop Result i want output is that program to print the data inside array if have 3,4,7 folder . i don't want use loop again and again . So i want print all json data array on file in once all dynamically.

I believe you need to create component that accepts folder through @Input field and this component will display current folder name and if folder has child folders it will iterate through them and use self (same component) to display every single folder (by passing every folder to the component via @Input field).

With such recursion you will not need to repeat your loops manually. Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM