angular - ngFor 与数组数组成角度
问题描述
- 项目清单:
jsonObject = [
{
place: 'place1',
fatherDetails: [
{name: 'place1_father1', adharId: 134567},
{name: 'place1_father2', adharId: 124567},
],
motherDetails: [
{name: 'place1_mother1', adharId: 123456},
{name: 'place1_mother2', adharId: 123457},
{name: 'place1_mother3', adharId: 123467},
],
},
{
place: 'place2',
fatherDetails: [
{name: 'place2_father1', adharId: 123567},
{name: 'place2_father2', adharId: 12567},
],
motherDetails: [
{name: 'place2_mother1', adharId: 1234567},
{name: 'place2_mother2', adharId: 1234567},
{name: 'place2_mother3', adharId: 1234567},
],
}
];
如何fatherDetails
使用 ngFor 循环 HTML 中的所有对象?基本上,我需要这样的东西:
<mat-option *ngFor = "let father of jsonObject">
{{father.name}}
</mat-option>
但是,这行不通。因为,它必须循环两次。
解决方案
注意您需要迭代第一个循环,第二个循环将在第一个循环的对象数组中进行迭代。
jsonObject = [{
place: 'place1',
fatherDetails: [{
name: 'place1_father1',
adharId: 134567
},
{
name: 'place1_father2',
adharId: 124567
},
],
motherDetails: [{
name: 'place1_mother1',
adharId: 123456
},
{
name: 'place1_mother2',
adharId: 123457
},
{
name: 'place1_mother3',
adharId: 123467
},
],
},
{
place: 'place2',
fatherDetails: [{
name: 'place2_father1',
adharId: 123567
},
{
name: 'place2_father2',
adharId: 12567
},
],
motherDetails: [{
name: 'place2_mother1',
adharId: 1234567
},
{
name: 'place2_mother2',
adharId: 1234567
},
{
name: 'place2_mother3',
adharId: 1234567
},
],
}
];
<tr *ngFor="let object of jsonObject;let i = index;">
<td>{{i}}</td>
<td * ngFor="let o of object.motherDetails">{{o}}</td>
</tr>
推荐阅读
- hadoop - 分布式 Hbase 启动失败,错误信息:服务器尚未运行
- java - Java 处理无效请求映射 url,包括解码
- wordpress - Peachpie wp-dotnet 项目的谷歌分析插件
- sql - 选择 SQL 中的最后一个完整列
- python - Python 单词检查器
- java - 当我输入 10 时,我的代码不会读取第 10 行,当我输入负数时如何退出程序?
- c# - 通过命令行创建 7-Zip 存档时创建逻辑文件夹结构
- javascript - TypeError:无法读取未定义的属性“通道”
- vue.js - 在 nuxt.js/vue.js 上每页加载不同的 css
- javascript - Discord.js 类型/声明扩展不起作用