How to implement For loop concept for schema(nested )

…衆ロ難τιáo~ 提交于 2019-12-13 04:14:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!