Angular 5 *ngFor array of objects












1














I have data like this:



Initial data:



var input = [
{ru: "R201", area: "211", unit: "211"},
{ru: "R201", area: "212", unit: "NONE"},
{ru: "R201", area: "HCC", unit: "NONE"}];


Result data:



var result = [
{area: ["211", "212", "HCC"],
ru: "R201",
unit: ["211", "NONE"]}];


I want to looping these data into template using ngFor, after some researches I'm getting stuck at this problem, cannot find a differ supporting object 'R201' of type 'string'. NgFor only supports binding to Iterables such as Arrays.



Here is my function:



  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 my template:



<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>&nbsp;{{ 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)">
&nbsp;{{ menu.unit }}
</span>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-item>
</ion-list>


Maybe someone could help me, thank you in advance.










share|improve this question




















  • 1




    Can you show the original dataMenu data that the function works on please?
    – rrd
    Nov 20 at 8:06










  • var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}];
    – Ruby Ravenford
    Nov 20 at 8:10










  • _.groupBy creates an object. Unless you provide a Symbol.Iterator, you won't be able to loop over an object (and even with that, I'm not sure you can, I haven't tested it yet).
    – trichetriche
    Nov 20 at 8:13
















1














I have data like this:



Initial data:



var input = [
{ru: "R201", area: "211", unit: "211"},
{ru: "R201", area: "212", unit: "NONE"},
{ru: "R201", area: "HCC", unit: "NONE"}];


Result data:



var result = [
{area: ["211", "212", "HCC"],
ru: "R201",
unit: ["211", "NONE"]}];


I want to looping these data into template using ngFor, after some researches I'm getting stuck at this problem, cannot find a differ supporting object 'R201' of type 'string'. NgFor only supports binding to Iterables such as Arrays.



Here is my function:



  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 my template:



<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>&nbsp;{{ 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)">
&nbsp;{{ menu.unit }}
</span>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-item>
</ion-list>


Maybe someone could help me, thank you in advance.










share|improve this question




















  • 1




    Can you show the original dataMenu data that the function works on please?
    – rrd
    Nov 20 at 8:06










  • var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}];
    – Ruby Ravenford
    Nov 20 at 8:10










  • _.groupBy creates an object. Unless you provide a Symbol.Iterator, you won't be able to loop over an object (and even with that, I'm not sure you can, I haven't tested it yet).
    – trichetriche
    Nov 20 at 8:13














1












1








1







I have data like this:



Initial data:



var input = [
{ru: "R201", area: "211", unit: "211"},
{ru: "R201", area: "212", unit: "NONE"},
{ru: "R201", area: "HCC", unit: "NONE"}];


Result data:



var result = [
{area: ["211", "212", "HCC"],
ru: "R201",
unit: ["211", "NONE"]}];


I want to looping these data into template using ngFor, after some researches I'm getting stuck at this problem, cannot find a differ supporting object 'R201' of type 'string'. NgFor only supports binding to Iterables such as Arrays.



Here is my function:



  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 my template:



<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>&nbsp;{{ 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)">
&nbsp;{{ menu.unit }}
</span>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-item>
</ion-list>


Maybe someone could help me, thank you in advance.










share|improve this question















I have data like this:



Initial data:



var input = [
{ru: "R201", area: "211", unit: "211"},
{ru: "R201", area: "212", unit: "NONE"},
{ru: "R201", area: "HCC", unit: "NONE"}];


Result data:



var result = [
{area: ["211", "212", "HCC"],
ru: "R201",
unit: ["211", "NONE"]}];


I want to looping these data into template using ngFor, after some researches I'm getting stuck at this problem, cannot find a differ supporting object 'R201' of type 'string'. NgFor only supports binding to Iterables such as Arrays.



Here is my function:



  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 my template:



<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>&nbsp;{{ 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)">
&nbsp;{{ menu.unit }}
</span>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-item>
</ion-list>


Maybe someone could help me, thank you in advance.







json angular typescript ionic-framework underscore.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 8:11

























asked Nov 20 at 8:02









Ruby Ravenford

66




66








  • 1




    Can you show the original dataMenu data that the function works on please?
    – rrd
    Nov 20 at 8:06










  • var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}];
    – Ruby Ravenford
    Nov 20 at 8:10










  • _.groupBy creates an object. Unless you provide a Symbol.Iterator, you won't be able to loop over an object (and even with that, I'm not sure you can, I haven't tested it yet).
    – trichetriche
    Nov 20 at 8:13














  • 1




    Can you show the original dataMenu data that the function works on please?
    – rrd
    Nov 20 at 8:06










  • var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}];
    – Ruby Ravenford
    Nov 20 at 8:10










  • _.groupBy creates an object. Unless you provide a Symbol.Iterator, you won't be able to loop over an object (and even with that, I'm not sure you can, I haven't tested it yet).
    – trichetriche
    Nov 20 at 8:13








1




1




Can you show the original dataMenu data that the function works on please?
– rrd
Nov 20 at 8:06




Can you show the original dataMenu data that the function works on please?
– rrd
Nov 20 at 8:06












var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}];
– Ruby Ravenford
Nov 20 at 8:10




var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}];
– Ruby Ravenford
Nov 20 at 8:10












_.groupBy creates an object. Unless you provide a Symbol.Iterator, you won't be able to loop over an object (and even with that, I'm not sure you can, I haven't tested it yet).
– trichetriche
Nov 20 at 8:13




_.groupBy creates an object. Unless you provide a Symbol.Iterator, you won't be able to loop over an object (and even with that, I'm not sure you can, I haven't tested it yet).
– trichetriche
Nov 20 at 8:13












1 Answer
1






active

oldest

votes


















0














You can manipulate your result according to this.



var grd = .chain(input)
.groupBy('ru')
.map(function(value, key) {
return {
ru: key,
area: _.uniq(_.pluck(value, 'area')),
unit: _.uniq(_.pluck(value, 'unit'))
}
}).value();

this.groupBy = ;

for(let key in grd){
groupby.push({key: key, values:grd[key]});
}





share|improve this answer























  • why not let key in grd instead of key in grd?
    – Ruby Ravenford
    Nov 20 at 8:41











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388598%2fangular-5-ngfor-array-of-objects%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can manipulate your result according to this.



var grd = .chain(input)
.groupBy('ru')
.map(function(value, key) {
return {
ru: key,
area: _.uniq(_.pluck(value, 'area')),
unit: _.uniq(_.pluck(value, 'unit'))
}
}).value();

this.groupBy = ;

for(let key in grd){
groupby.push({key: key, values:grd[key]});
}





share|improve this answer























  • why not let key in grd instead of key in grd?
    – Ruby Ravenford
    Nov 20 at 8:41
















0














You can manipulate your result according to this.



var grd = .chain(input)
.groupBy('ru')
.map(function(value, key) {
return {
ru: key,
area: _.uniq(_.pluck(value, 'area')),
unit: _.uniq(_.pluck(value, 'unit'))
}
}).value();

this.groupBy = ;

for(let key in grd){
groupby.push({key: key, values:grd[key]});
}





share|improve this answer























  • why not let key in grd instead of key in grd?
    – Ruby Ravenford
    Nov 20 at 8:41














0












0








0






You can manipulate your result according to this.



var grd = .chain(input)
.groupBy('ru')
.map(function(value, key) {
return {
ru: key,
area: _.uniq(_.pluck(value, 'area')),
unit: _.uniq(_.pluck(value, 'unit'))
}
}).value();

this.groupBy = ;

for(let key in grd){
groupby.push({key: key, values:grd[key]});
}





share|improve this answer














You can manipulate your result according to this.



var grd = .chain(input)
.groupBy('ru')
.map(function(value, key) {
return {
ru: key,
area: _.uniq(_.pluck(value, 'area')),
unit: _.uniq(_.pluck(value, 'unit'))
}
}).value();

this.groupBy = ;

for(let key in grd){
groupby.push({key: key, values:grd[key]});
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 10:30

























answered Nov 20 at 8:29









Sameer

16519




16519












  • why not let key in grd instead of key in grd?
    – Ruby Ravenford
    Nov 20 at 8:41


















  • why not let key in grd instead of key in grd?
    – Ruby Ravenford
    Nov 20 at 8:41
















why not let key in grd instead of key in grd?
– Ruby Ravenford
Nov 20 at 8:41




why not let key in grd instead of key in grd?
– Ruby Ravenford
Nov 20 at 8:41


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388598%2fangular-5-ngfor-array-of-objects%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?