Angular4材料mdmenu

时间:2017-10-03 07:06:26

标签: json angular material

我正在尝试使用嵌套的Angular4-Material菜单(md-menu)。在线示例 - https://material.angular.io/components/menu/overview - 如下所示:

    <button md-button [mdMenuTriggerFor]="animals">Animal index</button>
    <md-menu #animals="mdMenu">
      <button md-menu-item [mdMenuTriggerFor]="vertebrates">Vertebrates</button>
      <button md-menu-item [mdMenuTriggerFor]="invertebrates">Invertebrates</button>
    </md-menu>
    <md-menu #vertebrates="mdMenu">
      <button md-menu-item [mdMenuTriggerFor]="fish">Fishes</button>
      <button md-menu-item [mdMenuTriggerFor]="amphibians">Amphibians</button>
      <button md-menu-item [mdMenuTriggerFor]="reptiles">Reptiles</button>
      <button md-menu-item>Birds</button>
      <button md-menu-item>Mammals</button>
    </md-menu>
    <md-menu #invertebrates="mdMenu">
      <button md-menu-item>Insects</button>
      <button md-menu-item>Molluscs</button>
      <button md-menu-item>Crustaceans</button>
      <button md-menu-item>Corals</button>
      <button md-menu-item>Arachnids</button>
      <button md-menu-item>Velvet worms</button>
      <button md-menu-item>Horseshoe crabs</button>
    </md-menu>

我的菜单数据来自嵌套的JSON - 父子孙子场景(L1,L2和L3菜单)。当我尝试使用嵌套的JSON数据时,我会收到错误,因为无法读取L3菜单。

    <ul class="navbar-nav">
        <li class="nav-item active" *ngFor="let x of navData">
            <button md-button class="nav-link" [mdMenuTriggerFor]="l2">{{x.name}}</button>
            <md-menu #l2="mdMenu">
                <button md-menu-item *ngFor="let y of x.l2" [mdMenuTriggerFor]="l3">{{y.title}}</button>
            </md-menu>
            <md-menu #l3="mdMenu">
                <button md-menu-item *ngFor="let z of y.l3">{{z}}</button>
            </md-menu>
        </li>
    </ul>

似乎“md-menu”不维护父子层次结构。有关这个问题的任何帮助吗?

提前致意并表示感谢。

JSON DATA就像这样[{“name”:“Hub”},{“name”:“Workspace”,“l2”:[{“title”:“Organization”,“l3”:[“hierarchy” ,“成本中心”,“企业入职”,“用户”,“角色”,“政策标准”,“环境类型”]},{“标题”:“资源”,“l3”:[“ provider-management“,”accounts“,”metric-provider“,”provider-roles“,”resource-classification“,”resource-management“,”images“,”template“,”config-management“,”provider- locations“,”provider-template“]}]}]

0 个答案:

没有答案