angular - ngFor 在打字稿中的嵌套地图
问题描述
我想遍历嵌套映射以从第二个映射的列表中获取值。
地图:
public groupedItemMap: Map<string, Map<string, ItemSearchResult[]>>;
地图结构:
Map
--[[Entries]]
----0
-------key - number (if occured once or is duplicate)
-------value - Map
---------[[Entries]]
-----------key - itemNumber
-----------value - List of object(s) with parameters 'id',..'name' and so on and same itemNumber
++++++++++++if itemNumber is different there are more objects of the same type with different itemNumber
-----------key
-----------value
我想从中访问对象列表。
<!-- Here keyvalue is not possible on groupedItemMap -->
<div *ngFor="let group of groupedItemMap.entries()">
<span>{{ group.key }}</span>
<div *ngFor="let items of group| keyvalue">
<span>{{ items.key }}</span>
<div *ngFor="let item of items.value">
<span>{{ item.id }}</span>
</div>
</div>
</div>
如果我不使用它keyvalue
,groupedItemMap
我只能通过 4 个*ngFor
循环访问它,并且map.entries()
循环我的 html 标记中的所有项目。
解决方案
您可能需要同时使用keyvalue
这两个循环。尝试以下
<li class="list-group-item" *ngFor="let first of groupedItemMap">
<div *ngFor="let second of first | keyvalue">
<div *ngFor="let item of second.value | keyvalue">
<!-- Here `item.value` is an array. So you possibly need another *ngFor. Test with `json` pipe -->
<strong innerHTML="{{ item.key }} x {{ item.value | highlight: highlight }}">
</strong>
<span class="text-description margin-bottom-5"
innerHTML="{{ 'number' | translate }}: {{ item.number|highlight:highlight }}"></span>
</div>
</div>
推荐阅读
- kivy - WSL 上的 Buildozer 无法识别手机
- spring - 如何通过我们自己的具有承担角色的凭证提供者实现来覆盖 DefaultAWSCredentialsProviderChain
- c++ - 如何在不使用 OpenCV 函数的情况下旋转图像?(使用线性、Qubic 插值)
- go - golang包本地找不到
- date - 用道具 Vue3 观看
- c++ - 使用现代 C++ 的多线程惯用查找字符串中的第一个子字符串
- terraform - aws_instance 中的 Terraform 可扩展 user_data
- c++ - 假定对 Importer::Importer()、Importer::~Importer() 和 Importer::ReadFile(char const*, unsigned int) 的未定义引用
- spring - MongoDB 创建日期返回 null
- google-api - Oauth 中没有“高级设置”按钮