[英]Why is this data showing undefined when there are clearly values?
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.