我正在制作一个动态权限列表,该如何使用来自以下位置的“项目”:
<div *ngFor="let item of PermissionsList.T1">
<!-- Some code here -->
</div>
在内部ngFor
循环中。我尝试了以下方法和其他类似的方法:
<p *ngFor="let item2 of PermissionsList.{{item}}">test</p>
PermissionsList
示例如下:
T1: Array [ "Business", "Recreation", "Vehicles" ]
Recreation: Array [ "Hunting", "Leisure" ]
Hunting: Array [ "Big_Game", "Bird", "Pest" ]
Big_Game: Array [ "Moose", "Elk" ]
Pest: Array [ "Wild Boar", "Fox" ]
Bird: Array [ "Geese", "Sharp-tailed grouse" ]
Leisure: Array [ "Hiking", "Bird Watching" ]
Business: Array [ "Trapping", "Utility", "Construction"]
Vehicles: Array [ "Half_ton", "ATV", "SnowMobile" ]
答案 0 :(得分:1)
如果PermissionsList
是Array
的{{1}},而您要遍历第二个数组,则可以尝试以下操作:
Arrays
如果<div *ngFor="let permission of PermissionsList">
<div *ngFor="let item of permission ">
{{ item }}
</div>
</div>
是PermissionsList
的{{1}},而您只想显示Object
,请尝试以下操作:
Arrays