2017-05-23 1 views
4

클라이언트 목록을 표시하는 뷰를 만들려고합니다. 객체라는 점과 Ionic의 html 유형 때문에 문제가 발생합니다.이오닉 2 : 객체 목록을 반복합니다.

여기 내 객체입니다

x = { Consultation: [{name: "Joe Smith}, {name: "Jane Doe"}], 
    Re-evaluation: [{name: "Joe Smith2}, {name: "Jane Doe2"}], 
    Meeting: [{name: "Joe Smith3}, {name: "Jane Doe3"}], 
    Testing: [{name: "Joe Smith4}, {name: "Jane Doe4"}] 
} 

나는 appointment_typesObject.keys(x) 일명 ["Consultation", "Re-evaluation", "Meeting", "Testing"]을 정의합니다. 내보기에서

:

<ion-list> 
    <ion-list-header *ngFor="let type of appointment_types">{{ type }}</ion-list-header> 

    <!-- type is no longer defined after ion-list-header closes --> 
    <ion-item-sliding class="shaded-slider" *ngFor="let client of appointment_types[type]"> 
    <ion-item>{{ client.name }}</ion-item> 
    </ion-item-sliding> 
</ion-list> 

내가 appointment_types 루프 내에서 체류 할 수있는 뭔가가 있나요?

<ion-list *ngFor="let type of appointment_types"> 

을하고 type하고 원래 개체 x이있을 때 다음, 당신은 같은 내부 배열로 x 객체를 반복 할 수

+0

Iin이 명령이야 . – developer033

+0

모두를 포함하는 ngFor와 함께 div를 추가하십시오. like

답변

4

당신은 ion-list에서 유형의 당신의 반복을함으로써이 문제를 해결할 수 예 :

<ion-list *ngFor="let type of appointment_types"> 
    <ion-list-header >{{ type }}</ion-list-header> 
    <ion-item-sliding class="shaded-slider" *ngFor="let client of x[type]"> 
    <ion-item>{{ client.name }}</ion-item> 
    </ion-item-sliding> 
</ion-list> 

다음은`이온 list`에`처음`* ngFor` <이온 아이템 sliding`, 당신은 넣어해야`에서 type` * 객체 *에 액세스 할 수있는 PLUNKER

+0

나는 생각하고 있었다. 그러나 그들의 ''요소가 미리 결정된 CSS를 가지고 있고 각 반복마다 실제로 목록을 다시 만들고 싶다면 확실하지 않다. –

+0

의견에 의미가 무엇인지 이해하지 못한다. ,하지만 그것은 아주 잘할 수 있습니다. 왜냐하면 나는 여기에서 제외하고는 이온을 사용하지 않았습니다. :) 그러나 어떻게 든 이것을 다르게 구축하고 싶다면, 이것을 '그러나 나는 이것이 코드의 나머지 부분에 어떻게 영향을 미치는지 css-wise하지 않습니다. 그러나 실험을 통해 어떻게 재생되는지 확인할 수 있습니다 :) – Alex