Here is the data I am working with:
Initial set of data:
var input = [
{ru: "R201", area: "211", unit: "211"},
{ru: "R201", area: "212", unit: "NONE"},
{ru: "R201", area: "HCC", unit: "NONE"}];
Desired result data:
var result = [
{area: ["211", "212", "HCC"],
ru: "R201",
unit: ["211", "NONE"]}];
I am encountering an issue while trying to loop through this data in a template using ngFor. The error message states that it cannot find a differ supporting object 'R201' of type 'string'. NgFor only supports binding to Iterables such as Arrays.
This is the function I have written:
this.groupBy = _
.chain(input)
.groupBy('ru')
.map(function(value, key) {
return {
ru: key,
area: _.uniq(_.pluck(value, 'area')),
unit: _.uniq(_.pluck(value, 'unit'))
}
})
.value();
And here is the corresponding template code:
<ion-list no-lines class="menus">
<ion-item ion-item *ngFor="let p of groupBy; let i=index" (click)="toggleLevel1('idx'+i)" [ngClass]="{active: isLevel1Shown('idx'+1)}">
<ion-row>
<ion-col col-9>
<span ion-text>
<strong>{{ p.ru }}</strong>
<ion-icon [name]="isLevel1Shown('idx'+i) ? 'arrow-dropdown' : 'arrow-dropright'" float-right></ion-icon>
</span>
<ion-list no-lines *ngIf="isLevel1Shown('idx'+i)">
<ion-item no-border *ngFor="let menu of p.ru; let i2=index" text-wrap (click)="toggleLevel2('idx'+i+'idx'+i2)" [ngClass]="{active: isLevel2Shown('idx'+i+'idx'+i2)}"><br>
<span ion-text>
<strong> {{ menu.area }}</strong>
<ion-icon [name]="isLevel2Shown('idx'+i+'idx'+i2) ? 'arrow-dropdown' : 'arrow-dropright'" float-right></ion-icon>
</span>
<ion-list no-lines *ngIf="isLevel2Shown('idx'+i+'idx'+i2)">
<ion-item no-border text-wrap><br>
<span ion-text (click)="openEquipmentPage(p.dataRu,menu.area,menu.unit)">
{{ menu.unit }}
</span>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-item>
</ion-list>
I would appreciate any help or guidance on resolving this issue. Thank you in advance!