2017-11-07 2 views
-3

새로운 각도 2. 나는 Json 파일을 가져올 수 있습니다. 일부 json 파일을 얻을 수 있지만 json 파일 안의 배열은 가져올 수 없습니다. 예를 들어, 두 번째 UL의 첫 번째 UL 및 IMU 장치에서 GPS 장치를 시각화하고 싶습니다. 그들이 배열되어 있더라도 목록 둘 모두에 IMU 장치의 동일한 데이터가 나타납니다.각도 2 ngFor for 중첩 된 json

JSON 파일

"config" : [ 
    { 
     "id"  : "gps_device", 
     "name" : "GPS Device", 
     "type" : "String", 
     "widget" : "dropdown", 
     "fields" : [ "Disabled", "XSensIMU", "GenesysADMA"], 
     "default" : "Disabled" 
    }, 
    { 
     "id"  : "imu_device", 
     "name" : "IMU Device", 
     "type" : "String", 
     "widget" : "dropdown", 
     "fields" : [ "Disabled1", "XSensIMU1", "GenesysADMA1"], 
     "default" : "XSensIMU" 
    } 
] 

//here I should get loop of GPS device array 
 
<h1>Gps Device</h1> 
 
<ul *ngFor="let drop of config[0]"> 
 
    <li *ngFor="let sub of drop.fields"> {{sub}}</li> 
 
<ul> 
 
//here array of IMU device 
 

 
<h1>IMU Device</h1> 
 
<ul *ngFOr="let drop1 of config[1]"> 
 
    <li *ngFOr="let sub1 of drop.fields"> {{sub1}}</li> 
 
<ul>

+0

문제는 무엇입니까? –

+0

두 목록을 보여 드리고 싶습니다. 데이터는 json 파일에서 가져온 것입니다. 첫 번째 목록 데이터는 config [0] .fields이고 두 번째 목록 데이터는 config [1] .fields입니다. –

+0

'let sub1 of drop1.fields "' – echonax

답변

0

2 개 그룹으로 장치를 분리하기 위해이 코드를 시도하십시오 : 설정에

<div *ngFor="let drop of config"> 
    <ng-container *ngIf="drop.id === 'imu_device'; else gpsBlock"> 
    <h1>IMU Device</h1> 
    <ul> 
     <li *ngFOr="let sub1 of drop.fields"> {{sub1}}</li> 
    </ul> 
    </ng-container> 
    <ng-container #gpsBlock> 
    <h1>Gps Device</h1> 
    <ul> 
     <li *ngFOr="let sub1 of drop.fields"> {{sub1}}</li> 
    </ul> 
    </ng-container> 
</div> 

당신 루프, 및 GPS 또는 IMU 사업부에 조건부로 기기 표시

편집 : 또는 당신이 이런 식으로 일을 할 수

<ng-container *ngFor="let drop of configs"> 
    <h1>{{drop.name}}</h1> 
    <ul> 
     <li *ngFor="let field of drop.fields">{{field}}</li> 
    </ul> 
    </ng-container> 
+0

문제를 편집에 대한 Thnaks는 두 번째 루프가 될 때마다이다 –

+0

두 번째 방법을 확인해 봐, 그것은 당신의 해결책이 될 수 있습니다 – Boulboulouboule

0

당신은 *ngFor

config[0]으로는 동일합니다 사용하여 개체를 반복 할수 없어

{ 
    "id"  : "gps_device", 
    "name" : "GPS Device", 
    "type" : "String", 
    "widget" : "dropdown", 
    "fields" : [ "Disabled", "XSensIMU", "GenesysADMA"], 
    "default" : "Disabled" 
} 

어느 이 아니고, iterable이 아닙니다.

그래서 배열을입니다 config 배열을 반복

<h1>IMU Device</h1> 
<ul *ngFOr="let drop1 of config"> 
    <li *ngFOr="let sub1 of drop.fields"> {{sub1.name}}</li> 
<ul> 
+0

사실 내가 config [0]을 할 수 없습니다. 두 다른 목록을 얻으려면 다른 방법이 있습니까 –

+0

@ JotaToledo 또한 lookis 좋은 경우 그것을 표시 :),이 접근법과 –