I have passed a List from Java to Velocity templating. Later (in Velocity) I loop through the list of items and create a Javascript object as follows:
<script>
var objectsForSelection = {};
#foreach($carrier in $TableConfigList) #if(${carrier.getHtmlTemplate()}=="") #set($jsonDescriptorWithHtml =${carrier.getJsonTemplateList().toString()}) objectsForSelection['$carrier.getOption()'] ={}; objectsForSelection['$carrier.getOption()']['fields']=JSON.parse('$jsonDescriptorWithHtml'); #end
#end
</script>
This script however is only executed when:
Therefore the question is:
How can I pass data from velocity context to Javascript, and bind the data when the screen containing the Customfield is loaded?
Create page elements (hidden or visible depending on the design) that is populated by data in the velocity variables. You can then get values from the page elements in Javascript as you always do.
@Jobin Kuruvilla thanks for your answer!
It is important to save a JSON object within single quotes, hence avoiding conflicts between begin and end quotes and JSON quotes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.