简体   繁体   English

无法访问对象的属性

[英]Cannot access properties of object

I have ran into a very weird issue I cannot seem to fix. 我遇到了一个我似乎无法解决的非常奇怪的问题。 Basically I am taking a CSV file and parsing it into a JSON object to hold in my redux store. 基本上,我要获取一个CSV文件并将其解析为JSON对象以保存在我的redux存储中。 I have the parsing and everything working...or so it looks like it is working and everything compiled into a nice JSON object sitting in my store. 我已经进行了解析,并且一切正常……或者看起来一切正常,并且一切都编译成了一个漂亮的JSON对象,位于我的商店中。

在此处输入图片说明

When I map over each item and log the object in my component it also seems to look correct and I have access to everything I need...so it looks. 当我在每个项目上映射并将对象记录在组件中时,它看起来也很正确,并且可以访问所需的所有内容,因此看起来很不错。

在此处输入图片说明

The issue is when I try to use a property from those objects I get undefined no matter what. 问题是,当我尝试使用那些对象的属性时,无论如何我都无法定义。 So for example console.log(weatherData[i]) or console.log(weatherData.keyname) I can log the object as seen above. 因此,例如console.log(weatherData[i])console.log(weatherData.keyname)我可以记录该对象,如上所示。 However when I try to log something like this console.log(weatherData[i].capital) or console.log(weatherData.keyname.capital) I get undefined. 但是,当我尝试记录类似console.log(weatherData[i].capital)console.log(weatherData.keyname.capital)我不确定。

I have no idea why this is happening and am very lost now, so if anyone has any ideas please let me know. 我不知道为什么会这样,现在迷失了,所以如果有人有任何想法,请告诉我。 I also have used componentWillMount and 'setTimeout' to ensure I have all the data before requesting it, but that doesn't fix anything for me either 我还使用了componentWillMount和'setTimeout'来确保在请求它之前我已经拥有了所有数据,但这也不能解决任何问题

Just found the issue, was very stupid but the keys on my object had double quotes around them which was causing issues when trying to target them! 刚发现问题,这很愚蠢,但是我对象上的键周围有双引号,这导致在尝试定位它们时出现问题! Couldn't tell since inspect and redux tool both also format with double quotes 无法知道,因为inspect和redux工具都使用双引号格式化

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

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