【发布时间】:2021-02-26 10:11:36
【问题描述】:
当我从 API 检索数据时,会显示“名字”和“姓氏”值。但是“jobTitle”值没有显示在表格中,但它在控制台框中显示为一个数组。请帮我解决这个问题
这是 visibility.ts 文件:
export class VisibilityComponent implements OnInit {
pmDetails1: IEmployee[];
constructor(private userService: UserService) {}
ngOnInit() {
this.userService.getAllUsers().subscribe((pmDetails1: IEmployee[]) => {
this.pmDetails1 = pmDetails1;
console.log(pmDetails1);
console.log(pmDetails1[0].jobTitle);
});
}
}
这是 HTML 文件
<div>
<cdk-virtual-scroll-viewport itemSize="50" class="dialogbox-viewport">
<table class="table table-light" style="border: 1px solid">
<thead style="background-color: aqua">
<tr>
<th>Select</th>
<th>Name</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let p of pmDetails1">
<td>
<input type="checkbox" value="{{p.firstName}}" (change) = "onSelectedEmployee($event)" [checked]="check" />
</td>
<td>{{ p.firstName }} {{ p.lastName }}</td>
<td>{{ p.jobTitle }}</td>
</tr>
</tbody>
</table>
</cdk-virtual-scroll-viewport>
</div>
这是 IEmployee.ts 文件
export interface IEmployee {
userId: any;
firstName: string;
jobTitle: any;
lastName: String;
}
这是输出:
![在此处输入图片描述][1]
这里是“console.log(pmDetails1)”
![在此处输入图片描述][2]
这里是“console.log(pmDetails[0].jobTitles)”
我想在表格的 Role 列中显示 jobTitlesName。我是 Angular 的初学者。请帮我做
【问题讨论】:
-
谁在后端创建该对象?根据您的图像,
jobTitles不是数组,而是具有自身多个属性的对象。那么你想如何为你的视图字符串化该对象呢?
标签: javascript angular typescript