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?
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?
but why is console.log(self.data) working but not 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!)...
I have a feeling that @Dinesh Kumar's comment is on the right track, you're calling these functions after each other:
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.