【发布时间】:2020-02-27 21:12:52
【问题描述】:
我正在开发一个 Angular 8 应用程序,我现在必须在表格中显示注册用户。我正在使用ng2-smart-table 向用户展示,但我有一个问题:后端的响应显然是一个数组,但每个数组都有一个对象,我需要获取每个数组的属性(本例中的名称) .
这是我的代码:
this.mainService.getAllUsers().subscribe(res => {
console.log(res);
this.users = res;
this.source = new LocalDataSource(this.users);
res 的格式是以下数组:
{
_id: "5e5688bd1ef392001775c8c5"
nombre: "NICOLAS"
apellido: "SANABRIA"
email: "nico@ex.co"
nivel: 1
cargo: "Gerente EAP"
password: "$2a$10$jvqdJnIRKC4C9b5oSdmguOZA.UqqV.B7BnN1RhoMelFUk750K5BBW"
empresa: {_id: "5e5688bc1ef392001775c8c4", nombre: "P4", tipo: "EAP", estado: "pendiente", createdAt: "2020-02-26T15:03:24.638Z", …}
estado: "pendiente"
createdAt: "2020-02-26T15:03:25.067Z"
}
我需要属性的对象是“empresa”
感谢您的帮助
【问题讨论】:
-
res[index].empresa?其中index来自 for-loop/forEach -
您想要一组 emprasa 属性?
-
我的意思是,ng2-smart-table 会自动设置各个列中的数据,但是当我分配“empresa”数据时,我不想分配对象,而是分配名称, name 是一个属性。
标签: javascript angular frontend