angular - 如何从数组中获取结果?
问题描述
我有这样的 JSON:
{
"count": 1,
"rows": [
{
"hour_id": 1,
"report_date": "2019-10-22",
"teams_id": 5,
"team": {
"team_id": 5,
"full_name": "trytrys",
"is_active": true,
"masters": [
{
"master_id": 11,
"full_name": "sf",
"comment": "gff",
"date_work": "2019-06-22",
"teams_id": 5
},
{
"master_id": 10,
"full_name": "dgdf",
"comment": "hjgj",
"date_work": "2019-10-05",
"teams_id": 5
}
]
}
}
]
}
我需要从这个数组的主人那里获取数据。为了能够进一步找到最大场date_work
。怎么才能得到master上的数据?
ts:
private load() {
const params = {
search: this.search,
pageSize: this.pageSize,
page: this.page
};
this.loading = true;
this.isActive = false;
this._homeService.fetch(this.report_date, params).subscribe(repHours => {
this.loading = false;
this.isActive = true;
this.repHours = repHours.rows;
this.totalItems = repHours.count;
}, error => {
this.loading = false;
this.isActive = true;
console.log(error)
})
}
html:
<div *ngFor="let repHour of repHours">
{{repHour.team.masters.date_work}}
</div>
解决方案
只需使用 map 循环,例如:JSONDATA.rows.map(row => row.team.masters.map(master => console.log(master.date_work)));
推荐阅读
- ace-editor - 如何在 ace 编辑器中更改片段占位符变量的格式
- string - 字符串解压:降低时间和空间复杂度
- c# - 如何在 UWP 中运行带参数的 exe 文件
- javascript - 为什么我在 console.log 的第一个对象上得到 [Getter/Setter]?
- disqus - 如何让disqus授权api调用?
- asp.net - Word 16 文档以锁定模式打开
- excel - 如何修复我的代码以复制单元格值?
- azure-sql-database - .export 尝试在浏览器查询文本框中执行时返回错误“无法解析查询”
- flask - 无法使用 axios 向 Flask 应用程序发送 POST 请求
- javascript - 如何限制用户在移动字段中仅输入 10 个字符