0

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.

1
  • can you post ELC_OS_Portal_SimpleForm_Controller controller code ?
    – Arabinda
    Apr 2, 2019 at 2:57

1 Answer 1

0

I didn't find any way to pass Map> from controller to JavaScript. I solved this issue by creating a String out of List where values of the list are separated by ; then I passed Map. In JavaScript I used split method to create a list out of value string.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .