ESRI JS API

913
4
07-15-2021 09:17 AM
Ross_1
by
New Contributor II

 

function buildPopupContent() {

        var aep = [
            {
                'featureLayer': meanAnnualWaveResourceSelkie,
                'fieldInfos': [
                    {
                        'fieldName': 'Wave_Power',
                    }
                ]
            }
        ];


        console.log("buildPopupContent")

        

        let div = document.createElement("div");

        div.innerHTML =


            '<table><tr><td>AEP: <td>' + aep + '</td></tr>' +
            '<tr><td>Project Life: <td><input type="number" name="defaultProjectLife" id="defaultProjectLife" style="width: 7em" value="20" min=1 max=100/><span id="defaultProjectLife_errors"></span></td></tr>' +
            '<tr><td>Discount Rate: <td><input type="number" name="defaultDiscountRate" id="defaultDiscountRate" style="width: 7em" value="5" min=1 max=50/><span id="defaultDiscountRate_errors"></span></td></tr></table>' + '<BR>' +

            '<div id="calculate_lcoe"><button onclick="calc_te()">Calculate</button></div>' + '<BR>' +
            '<button></div>' +

            '<table><tr><td>LCOE: <td><input type="text" name="lcoe" id="lcoe" style="width: 7em" disabled /></td></tr></table>'
        
        return div;

    }
​

Hi all.

 

 
My issue is with trying to include inputs and run calculations from a feature layer with popupTemplate in JS API. The template will accept the attribute input in the title section of the popup but not in the contents section where it is just appearing as '[object Object]'. The image below shows what happens upon activating the popup. I need to call the attribute value from the feature layer into the contents section so that it can be used as another input to the calculation of the LCOE output.
 
Ross_1_0-1626365699362.png
 
Another brief way of describing the issue is that I am unable to pass a feature layer variable into the content builder function. I also attach a snippet of some of the relevant section of code here.
 
Ross_1_1-1626365699363.png

 

Thanks for your help!

Ross 

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Can you post your code using the "Insert code sample" tool instead of in an image?

https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552

Ross_1
by
New Contributor II

Done! 

0 Kudos
ReneRubalcava
Frequent Contributor

Your "aep" variable is an array, not a string value. If you want it to read the field, you can pass aep as "{WavePower}" and it will read the field that way. That syntax is described here.

https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html

0 Kudos
Ross_1
by
New Contributor II

Hi Rene, 

 

Thank you, but unfortunately I have tried that and it does not fix the problem. 

 

Ross

0 Kudos