[英]How to access nested arrays of objects
I am subscribing to my data from an http get method: 我正在通过http get方法订阅我的数据:
getEds(): void {
this.edService.getEds()
.subscribe((eds: Education) => {
this.eds = eds.educationData;
console.log(this.eds:codeschool);
});
}
I am trying to display my courses for codeschool in an *ngFor loop but do not know how to access the data. 我正在尝试在* ngFor循环中显示代码学校的课程,但不知道如何访问数据。 My console log will show the entire array of objects so I know I am receiving the correct info.
我的控制台日志将显示对象的整个数组,因此我知道我收到了正确的信息。 I've tried various syntax:
我尝试了各种语法:
.subscribe((eds: any) => {
this.eds = eds.educationData.course;
.subscribe((eds: any) => {
this.eds = eds.educationData['codeschool'];
.subscribe((eds: any) => {
this.eds = eds.educationData.codeschool;
None of these syntax work and the log shows undefined. 这些语法都不起作用,并且日志显示未定义。 I found this page which has great info and what I tried to use as a baseline.
我发现此页面包含重要信息以及我尝试用作基准的页面。
Access / process (nested) objects, arrays or JSON 访问/处理(嵌套的)对象,数组或JSON
However, I do not know what is wrong or why I cannot get the data I need. 但是,我不知道出了什么问题或者为什么我无法获取所需的数据。 When I use
当我使用
.subscribe((eds: any) => {
this.eds = eds.educationData;
and I log out (this.eds), my log shows: 然后注销(this.eds),我的日志显示:
[{…}]
0:{codeschool: Array(14), egghead: Array(6)}
length:1
__proto__:Array(0)
Beyond this I haven't been able to get the data I want...... :( 除此之外,我还无法获取我想要的数据……:(
用这个 :
eds.educationData[0].codeschool
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.