问题
JSON schema format which is getting in response and stored it in buttonschema
{
"Name": "Test",
"layoutSections": [
{
"layoutColumns": [
{
"layoutItems": [
{
"name": "test",
},]
},]
},]
}
Html File to read Json schema
<div *ngFor="let Schema of buttonSchema?.layoutsections">
<div *ngFor="let Schema1 of Schema?.layoutcolumns">
<div *ngFor="let Schema2 of Schema1?.layoutItems">
</div>
</div>
</div>
Typescript File
buttonSchema: any;
ngOnInit() {
this.buttonSchema = this.authenticationService.buttonSchema;
**const s1 = this.buttonSchema.layoutsections;
const s2 = s1.layoutcolumns;
const s3 = s2.layoutItems;**
}
How to implement logic in typescript what is achieved with html.
回答1:
for (let i = 0; i < buttonSchema.layoutsections.length; i++) {
for (let j = 0; j < buttonSchema.layoutsections[i].layoutcolumns.length; j++) {
for (let k = 0; k < buttonSchema.layoutsections[i].layoutcolumns[j].layoutitems.length; k++) {
const item = buttonSchema.layoutsections[i].layoutcolumns[j].layoutitems[k];
}
}
}
回答2:
try this
<div *ngFor="let Schema of buttonSchema.layoutsections">
<div *ngFor="let Schema1 of Schema">
<div *ngFor="let Schema2 of Schema1">
</div>
</div>
</div>
来源:https://stackoverflow.com/questions/49303224/how-to-implement-for-loop-concept-for-schemanested