I am facing an issue with passing a Map object from my Grails controller to JavaScript. The code snippet in my controller is as follows:
def scoreValue = new HashMap<String,String>();
scoreValue.put("0","poor");
scoreValue.put("1","good");
...
return (view:'viewname', model:[scoreValue:scoreValue]);
I have been searching for a solution and came across this link pass a groovy array to javascript code, but it did not resolve my problem.
To try and solve the issue, I modified the return statement to
return (view:'viewname', model:[scoreValue:scoreValue as grails.converters.JSON])
and then inside my GSP view, I used the following code.
<g:if test="${scoreValue}">
var scoreValue=${scoreValue};
</g:if>
However, when I checked the HTML page, I saw the following output:
var scoreValue={"0":"Failure","1":"Poor"}
Any assistance on this matter would be greatly appreciated. Thank you!