Activity Forums Salesforce® Discussions How to pass List as a parameter to script?

  • Ravi

    Member
    July 28, 2016 at 8:03 pm

    Hi pranav,

    If you are using list of a sobject as getter ,setter in your controller then you can use it directly to your script.

    like

    var objectLis =  {!objectList};

    Second option is:

    1) Create the required list in the Apex Controller

    2) Create a Array in the JavaScript on the Page

    3) Use the repeat tag to populate this javascript.

    4) Use the populated list in any place in the JavaScript.

    Here is the sample code::

      <script>

    var requests = [];

    </script>

    <apex:repeat value="{!privacyRequests}" var="request">

    <script>

    requests.push('{!request}');

    </script>

    </apex:repeat>

     

    <script>

    window.onload = alertRequest;

    function alertRequest(){

    alert(requests[0]);

    }

    </script>

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos