4

I'm using ArcGIS javascript to pass some value from map service to front-end HTML.

I use ${parameter_name} syntax and pass it into HTML by

var html = [];
html.push('<div>Parameter value is ${parameter_name}</div>');
InfoTemplate.setContent(html);

So that my HTML page will show an InfoTemplate holding

 Parameter value is XXX

But now I want to get the value XXX and edit it before push it into html. How should I get the value in my javascript?

Taurus Dang
  • 551
  • 1
  • 4
  • 19

1 Answers1

2

You can use a function in the parametrized template like this below:

myEditFunction = function(parameterValue) {
    //here you can edit the value before returning it
    return parameterValue;
}

var html = [];
html.push('<div>Parameter value is ${parameter_name:myEditFunction}</div>');
InfoTemplate.setContent(html);

See the documentation vor API v3.26: https://developers.arcgis.com/javascript/3/jshelp/intro_formatinfowindow.html especially the Using custom functions section.

Below the Radar
  • 7,321
  • 11
  • 63
  • 142
  • I should thank you first! this is a new syntax for me. But I didn't suceed with arcgis js 3.21. Should I use later version? – Taurus Dang Nov 02 '18 at 13:22
  • According to the doc, my answer above should works in v3.26 (probably 3.21 too) see: https://developers.arcgis.com/javascript/3/jshelp/intro_formatinfowindow.html, what error do you get with this answer? – Below the Radar Nov 02 '18 at 13:49
  • Try my edited answer. I removed `var` before `myEditFunction` to make the function global – Below the Radar Nov 02 '18 at 13:52