简体   繁体   English

对象属性未定义

[英]Object properties are undefined

I get some data from my backend, and I want to make use of that data. 我从后端获取了一些数据,我想利用这些数据。

For some reason the properties are undefined when I try to access them, even though the data has come to the front-end. 由于某些原因,即使数据已经到达前端,当我尝试访问它们时,这些属性仍未定义。

This is what I get when I try to print them 这是我尝试打印它们时得到的


在此处输入图片说明


I've looked at similar questions, but none of the ones I saw had any answers that were a solution for me. 我看过类似的问题,但是我所看到的问题都没有任何答案可以解决我的问题。

What causes this? 是什么原因造成的? I use a promise to get the data(in case that has something to do with it). 我用一个承诺来获取数据(以防万一)。


this.driverService.getDrivers()
  .then((data: any) => {
    console.log(data); // prints the data like it should
    console.log(data['driverDataForDriverList']); // prints undefined
    console.log(data.driverDataForDriverList); // prints undefined
    this.driversData = data['driverDataForDriverList']; // assigns undefined...
  });

Please help, I'm a noob. 请帮助,我是菜鸟。 Thanks. 谢谢。

尝试console.log(data.data['driverDataForDriverList'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM