[英]Cannot read property of undefined, looking for object property
I am trying to get the dots
array from each object. 我试图从每个对象获取
dots
组。 However I keep getting cannot read property dots of undefined. 但是我一直无法读取未定义的属性点。
let events = fetchEvents[this.state.selectedDay || selected];
in my component I am using: 在我的组件中,我正在使用:
<EventCalendar
events={events.dots || []}
...
I'm my EventCalendar
component, this.props.events
is undefined
我是我的
EventCalendar
组件, this.props.events
undefined
render() {
const {
width,
virtualizedListProps,
initDate,
formatHeader,
upperCaseHeader = false
} = this.props;
const allDayEvents = this.props.events.filter(
event => event.allDayEvent == 1
);
fetchEvents
array: fetchEvents
数组:
2019-03-06: {dots: Array(2), disabled: false, selected: true, selectedColor: "#00CCCB", customStyles: {…}}
2019-03-07: {dots: Array(1), disabled: false, selected: true,
I believe you're not calling the intended JSON Object. 我相信您没有在调用预期的JSON对象。 Have you tried events['2019-03-07'].dots?
您是否尝试过event ['2019-03-07']。dots? Side Note: I would not use the date with a hyphen as your key.
旁注:我不会将带连字符的日期用作您的密钥。 You could remove the hyphen just to have digits instead since each key will be unique.
您可以删除连字符只是为了有数字,因为每个键都是唯一的。 Please refer to image below.
请参考下图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.