简体   繁体   English

当有明确的值时,为什么这些数据显示未定义?

[英]Why is this data showing undefined when there are clearly values?

On my page, I'm logging this: 在我的页面上,我正在记录以下内容:

console.log(self);
console.log(self.data.events);

The self is showing data, however self.data.events is showing undefined , how am I referencing this wrong? self显示数据,但是self.data.events显示undefined ,我怎么引用这个错误呢?

在此处输入图片说明

but why is console.log(self.data) working but not console.log(self.data.events)? 但是为什么console.log(self.data)有效,但console.log(self.data.events)不起作用?

As @Nick Parsons hinted in his comment, it might be because console.log behaves asynchronously in some browsers and will not log a "snapshot" at the time it was logged but will reflect updates on whatever is referenced, in this case self.data (which is initially defined as an empty object!)... 正如@Nick Parsons在他的评论中暗示的那样,这可能是因为console.log在某些浏览器中的行为是异步的,并且在记录日志时不会记录“快照”,但是会反映所引用内容的更新,在这种情况下为self.data (最初定义为空对象!)...

I have a feeling that @Dinesh Kumar's comment is on the right track, you're calling these functions after each other: 我觉得@Dinesh Kumar的评论正确无误,您会互相调用这些函数:

self.load_event_data();
self.load_zip_codes();
self.bind_events();
self.handle_filter_params();
self.cluster();

the issue is within self.cluster() but it is possible that the AJAX call you're making in self.load_event_data() is not be done yet when self.cluster() is called, so I'd suggest you try and call self.cluster() from within self.load_event_data() whenever you got data updated with the events. 问题是内self.cluster()但它是可能的AJAX调用你正在做的self.load_event_data()不被没有完成时self.cluster()被调用,所以我建议你尝试和呼叫每当您获取随事件更新的数据时,就会从self.cluster()获取self.load_event_data()

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

相关问题 明确定义后,为什么会得到未定义的“ toUpperCase”? - Why do I get 'toUpperCase' of undefined when it's clearly defined? 为什么数据显示未定义? - Why is data showing undefined? 为什么这是一个未定义的明确定义? - why is this a not defined when it clearly is? 为什么数据在ajax中显示未定义 - why data is showing undefined in ajax 为什么在明确定义对象后尝试打印它时,对象仍未定义? - Why is my object undefined when I try to print it when it is clearly defined? 为什么一个属性在记录时明确指向一个函数,但在同一行代码中引用时返回 undefined? - Why is a property clearly pointing to a function when logged but returning undefined when referenced in the same line of code? 在JS中明确定义“方法未定义”时 - Getting “method undefined” when it is CLEARLY defined in JS 为什么它显示未定义,如果 handleChange 本身有值 - Why is it showing undefined, if handleChange itself has values 为什么将这个非常明确定义的对象(在JSONLoader的回调中)读取为未定义? - Why does this very clearly defined (in callback to JSONLoader) object read as undefined? 网页中无显示,Angular清楚地显示了数组中的数据 - Nothing Displayed in web page with Angular clearly showing data in an array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM