0

I'm new to JavaScript (and most coding concepts in general) and this feels like there must be some simple solution that I just haven't found yet. I need information from a property of an object (not totally sure if I'm using those terms correctly). The object is created using ArcGIS API for Javascript.

console.log(view.popup);
console.log(view.popup.id);
console.log(view.popup.title);

By logging to the console (using the lines of code shown above) I can see that the properties exist because the below lines are logged to the console (from Line 1).

id: "17e2bf83e50-widget-1"

title: "k0"

I then log just the id property (Line 2) and it prints just the id property. However, if I try to log view.popup.title (Line 3), it logs 'null' to the console. Anything else I try to print out using console.log prints the same value found within view.popup. I just need to be able to use that value stored within view.popup.title and for some reason it seems like the only one where I can see that it's there but can't access it directly?

Edit: This does certainly seem to be the issue commented on by folks below, thanks for those links! I've been trying to do stringify (as suggested in Is Chrome’s JavaScript console lazy about evaluating objects?) but finding that it only finds some of the properties. I also made an attempt at making it wait to try to find it until the property is no longer null, but it's definitely somehow later in the code where that happens (the code just enters an infinite loop until there's a call error). View is generated using https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#popup (which is why I don't have a full understanding of what goes into it/when and how it makes that view.popup.title property)

    view = new SceneView({
        viewingMode: "local",
        map: scene,
        container,
        camera,
        spatialReference: {
            wkid:3089
        } 
    });
  • 1
    That's because the properties exist in the future, not at that point in the code where the console.log is. More than likely, this question describes your situation: https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call – Kevin B Jan 05 '22 at 21:12
  • 1
    Can you include the code responsible for generating `view`? – kingkupps Jan 05 '22 at 21:14
  • As you are new to javascript you would benefit from looking at some of the core concepts of the language. Based in your questing understanding how scope working in javascript and hoisting are good places to start. – nontechguy Jan 13 '22 at 04:12

1 Answers1

1

After learning here that it's related to view.popup.title not existing yet at the point of logging it, I moved over to the ArcGIS forum to ask about how view is generated and I got an answer that lets me access it! https://community.esri.com/t5/arcgis-api-for-javascript-questions/accessing-title-of-default-popup-created-for-a/m-p/1131210#M75813

view.popup.watch("title", () => {
  console.log(view.popup.title);
});