angular7 - 如何在angular7中存储多个json对象
问题描述
如何将多个json对象存储到angular7中的数组中?
我正在尝试保存 json 对象数组,如下所示:
employees: any;
ngOnInit() {
this.getemployee().subscribe
data => this.employees == data,
);
}
以下是我从后端得到的响应:
(32) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "59744", employee_name: "Sample API ", employee_salary: "18000", employee_age: "20", profile_image: ""}
1: {id: "59747", employee_name: "Test", employee_salary: "123", employee_age: "456", profile_image: ""}
2: {id: "59748", employee_name: "hello#amdon", employee_salary: "10000", employee_age: "35", profile_image: ""}
.......
解决方案
创建以下结构的对象数组。
//response data structure
export class ResponseData {
id:string
employee_name: string;
employee_salary: string;
employee_age: string;
profile_image:string;
}
组件.ts
export class Test implements OnInit {
responseData:ResponseData[]=[];
constructor(){ }
ngOnInit() {
this.getemployee().subscribe((data)=>{
if(data != null) {
console.log('response received');
this.responseData = data;
}
});
}
}
推荐阅读
- c# - 是否有数字“1”的输出?
- c# - 来自 URL 的 XML 请求和响应
- ruby - Ruby- 错误:无法构建 gem 原生扩展。gcc:错误:无法识别的命令行选项'-Wduplicated-cond'
- powerbi - Power BI 中的 DAX 是否与 Tableau 中的 LOD 相同
- r - 循环期间图不存储在列表中
- mysql - 2 个 SQL 请求。通过店铺的买家带上其他买家的名字
- owasp - 如何识别 REQUEST_BODY 中是否有任何附件以创建 ModSecurity 排除规则
- java - 为什么在 Eclipse 的 Servers 文件夹上有斧头标记
- node.js - 无法从节点 js 后端连接到 documentDB aws
- c# - C# UWP 在 InkCanvas 中单独渲染 InkStrokes