[英]TypeError: data is not iterable , using ngfor on nested array
rowData= [{ "label": "president", "contestants": [{ "name": "john key", "votes": 2 }, { "name": "john hi", "votes": 1 }, { "name": "john kl", "votes": 1 }] }, { "label": "organizer", "contestants": [{ "name": "michael skie", "votes": 3 }, { "name": "michael e", "votes": 1 }] }, { "label": "secretary", "contestants": [{ "name": "sampson eons", "votes": 2 }, { "name": "sampson mji", "votes": 2 }] }]
<div *ngIf="rowData.length >0"> <div *ngFor="let arr of rowData let i=index"> <div *ngFor="let elm of arr.contestants"> <ngx-charts-bar-vertical [view]="view" [scheme]="colorScheme" [results]="elm" [gradient]="gradient" [xAxis]="showXAxis" [yAxis]="showYAxis" [legend]="showLegend" [showXAxisLabel]="showXAxisLabel" [showYAxisLabel]="showYAxisLabel" [xAxisLabel]="xAxisLabel" [yAxisLabel]="yAxisLabel" (select)="onSelect($event)"> </ngx-charts-bar-vertical> </div> </div> </div>
I get an error that data is not iterable.我收到一个错误,即数据不可迭代。 Can someone help me
有人能帮我吗
I solved it by rearranging the json我通过重新排列 json 解决了这个问题
rowData = [ [{ "label": "president", "contestants": [{ "name": "john key", "votes": 2 }, { "name": "john hi", "votes": 1 }, { "name": "john kl", "votes": 1 }] }, { "label": "organizer", "contestants": [{ "name": "michael skie", "votes": 3 }, { "name": "michael e", "votes": 1 }] }, { "label": "secretary", "contestants": [{ "name": "sampson eons", "votes": 2 }, { "name": "sampson mji", "votes": 2 }] }] ]
<div *ngIf="rowData.length >0"> <div *ngFor="let arr of rowData let i=index"> <div *ngFor="let elm of arr.contestants"> <ngx-charts-bar-vertical [view]="view" [scheme]="colorScheme" [results]="elm" [gradient]="gradient" [xAxis]="showXAxis" [yAxis]="showYAxis" [legend]="showLegend" [showXAxisLabel]="showXAxisLabel" [showYAxisLabel]="showYAxisLabel" [xAxisLabel]="xAxisLabel" [yAxisLabel]="yAxisLabel" (select)="onSelect($event)"> </ngx-charts-bar-vertical> </div> </div> </div>
I moved the results rowData[0];我移动了结果 rowData[0]; and it solved my problem
它解决了我的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.