I want to pass a Map<String, List<String>>
from apex controller to javascript.
Here is my approach, I am using javascript remoting for it but it's not working.
controller function
@RemoteAction
global static Map<String, List<String>> getExceptions(){
System.debug('---------------exceptions----------->' + ELC_OS_Portal_SimpleForm_Controller.picklistExceptionMap);
return ELC_OS_Portal_SimpleForm_Controller.picklistExceptionMap;
}
Here I am populating static variable picklistExceptionMap in a non static method and then calling that method in constructor.
Then I am using calling this method in visualforce page
<script type="text/javascript">
function removeExceptionValues() {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.ELC_OS_Portal_SimpleForm_Controller.getExceptions}',
function(result, event){
console.log(result);
if (event.status) {
for (var key in result) {
if (result.hasOwnProperty(key)) {
for(var i=0; i<result[key].length; i++){
console.log(result[key][i]);
$("." + key).find('option:contains(' + result[key][i] + ')').remove();
}
}
}
} else if (event.type === 'exception'){}
},
{escape: true}
);
}
</script>
Finally calling this javascript method at the end of the page
<script>
$(document).ready(removeExceptionValues());
</script>
Problem is when I debug it in non static method I am able to get the value but is shows as null in @RemoteAction method.
Where am I wrong? If it's not the correct way please suggest a better approach.