如何从JSON获取Mat-menu

时间:2019-06-11 02:25:06

标签: javascript angular angular-material

 <mat-menu #metrics="matMenu">
    <ng-container *ngFor="let metric1 of objectKeys(my_metrics)">
        <button mat-menu-item [matMenuTriggerFor]="sub_menu_1">{{metric1}}</button>
        <mat-menu #sub_menu_1="matMenu">
          <button mat-menu-item [matMenuTriggerFor]="sub_menu_2"></button>
            <ng-container *ngFor="let metric2 of Object.keys(metric1)">
               <button  mat-menu-item [matMenuTriggerFor]="sub_menu_2">{{metric2}}</button>
               <mat-menu #sub_menu_2="matMenu">
                  <button *ngFor="let metric3 of metric1[metric2]" mat-menu-item>{{ metric3 }}</button>
               </mat-menu>
            </ng-container>
        </mat-menu>
        <!-- <mat-menu #sub_menu_1="matMenu">
                <button *ngFor="let metric2 of objectKeys(metric1)" mat-menu-item [matMenuTriggerFor]="metric2">{{metric2}}</button>
          </mat-menu> -->
    </ng-container>
  </mat-menu> 


  objectKeys = Object.keys;
      my_metrics = {
        'Remote copy metrics': {
            'IOPS': ['Read', 'Write'],
            'kbps': ['Read', 'Write'],
            'Service time': ['Read', 'Write'],
            'QLEN': ['Read', 'Write']
        },
        'Disk metrics': {
          'IOPS': ['Read', 'Write'],
          'kbps': ['Read', 'Write'],
          'Service time': ['Read', 'Write'],
          'QLEN': ['Read', 'Write']
        },
    }; 

我也添加了.ts文件。我已经仔细查看了示例代码,但无法正常工作。

如何从json动态获取mat-菜单?

附在图片下方以供参考。

sample image

0 个答案:

没有答案