0

I'm trying to make same dynamic content builder, but I'm not too experienced. This function sets the content for an infoTemplate of a sublayer(arcgisdynamicservice). It works well, if I hardcode the attribute field name like: graphic.attributes["SDE.SDE_ESRI_EP_FEATURECLASS_XX.FIELDNAME"]

I have never used regex in this type of app. Is it working at all, or did I miss something?

  function _getPopupTextContent(graphic) {
    let regex = /SDE.SDE_ESRI_EP_.*_XX.VALUE/;
    console.log(regex.test("SDE.SDE_ESRI_EP_FEATURECLASS_XX.FIELDNAME"));  
    //true      running when i'm clicking on the feature
    let popupContent = "<div style='padding:5px;background-color:rgb(251,183,46)'><b>" +
    "</b></div>" +
    "<table style='width:100%;'>"
      if (graphic.attributes[regex]){
        console.log("found") //not logging
        popupContent += "<tbody><tr><td id = 'attrtd'><b>AssetKKSCode</b></td><td id = 'attrtd''>" +
                          graphic.attributes[regex]
      }
      
        popupContent += "</td></tr>" +
                        "</td></tr>" +
                        "</a></td></tr>" +
                        "</tbody></table>"
    return popupContent;          
  }
3
  • Why do you think you need a regex? Graphic.attributes is a JavaScript object so you can use a string to get the attribute value, e.g. var myFieldName="MYFIELDNAME"; graphic.attributes[myFieldName]. Use curly braces to include an attribute value in a popupTemplate e.g. "<em>{MYFIELDNAME}</em>" – Berend Sep 1 '20 at 12:41
  • Sorry, i totally misnamed here the graphic.attribute properties' naming. I changed it now. So i dont care about the 'FEATURECLASS'. is just want to check if there is that fieldname. I changed my tactics, i'm trying now with this: for (const property in graphic.attributes){ let tableName = (property.toString()).split(/[.]/)[4]; if (graphic.attributes["SDE.SDE_ESRI_EP"+tableName+"MV.MYFIELDNAME]){ popupContent +=graphic.attributes["SDE.SDE_ESRI_EP"+tableName+"_MV.MYFIELDNAME"] this for loop sy adds this line to the popup to many times(len(obj.prop)) – gregi1991 Sep 1 '20 at 13:44
  • This curly braces linking didn't work for me somewhy. function joinAndCreateInfoTemplate(){ if (popupName == 'featureClassName'){ popupName = new InfoTemplate(); popupName.setTitle("<b>${SDE.SDE_ESRI_EP"+title+"."+re+"}</b>"); popupName.setContent(_getPopupTextContent); } subLyrObj.infoTemplates[subId] = { infoTemplate: new InfoTemplate(popupName) }; – gregi1991 Sep 1 '20 at 13:51
0
      function _getPopupTextContent(graphic) {       
    let popupContent = "<div style='padding:5px;background-color:rgb(251,183,46)'><b>" +
    "</b></div>" +
    "<table style='width:100%;'>"
    console.log(graphic.attributes)
    for (var property in graphic.attributes){
      var tableName = (property.toString()).split(/[_.]/)[4];
      var fieldName = (property.toString()).split(/[_.]/)[6];
        if(fieldName == 'FIELD1'){
          popupContent += "<tbody><tr><td id = 'attrtd'><b>Fieldname1</b></td><td id = 'attrtd''>" +
          graphic.attributes["SDE.SDE_ESRI_EP_"+tableName+"_MV."+fieldName]
        }
        if (fieldName == 'FIELD2'){
          popupContent += "<tbody><tr><td id = 'attrtd'><b>Fieldname2</b></td><td id = 'attrtd''>" +
          graphic.attributes["SDE.SDE_ESRI_EP_"+tableName+"_MV."+fieldName]
        }
    }
        popupContent += "</td></tr>" +
                        "</td></tr>" +
                        "</a></td></tr>" +
                        "</tbody></table>"
    return popupContent; 

So the regex was really unneeded for this, but i used it for proper slicing, and i made a variable for the tablename and for the fieldname. So i could check if the fieldname exists, but the name of the table doesn't matter when i check the object's props.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.