arrays - Angular 6 *ngFor 循环通过两个数组
问题描述
我有两个数组
firstArray= [{id: 1, name:'firstValue1'}, {id:2, name:'firstValue2'}]
secondArray= [{ "num": 1, "fullName": SecondValue1 , id:1}]
我想显示这样的数据
firstValue1 -------->> SecondValue1
firstValue2 -------->>
我如何在 [(ngModel)] 或输入或选择框中填充这两个数组?
感谢您的时间和回复!
解决方案
而不是维护secondArray
为Array
将其转换为HashMap
例子
firstArray = [
{ id: 1, name:'firstValue1' },
{ id: 2, name:'firstValue2' }
];
secondArray = {
'1': { "num": 1, "fullName": "SecondValue1", id: 1 },
'2': { "num": 1, "fullName": "SecondValue2", id: 2 },
}
html
<div *ngFor="let item of firstArray">
<p>{{item.name}} --> {{secondArray[item.id]?.fullName}}</p>
</div>
推荐阅读
- flutter - 如何在颤动的文本字段中创建输入掩码
- reactjs - 如何在我的 React 应用程序中引用位于应用程序目录之外的本地图像?
- javascript - Running a While function again, only if specific data has been loaded
- c# - 在 RazorLight 中将 html 渲染为字符串
- ruby-on-rails - 在 Ruby 中使用 gsub 在双引号之间插入空格
- c# - 如何等待 WPF UI?
- python - 如何阻止while循环在输出中重复?
- java - 用户以编程方式更改应用默认短信
- python - Pandas:查找最近的经纬对
- java - spring security:来自后端另一个应用程序的会话身份验证