+ Start a Discussion
GramGram 

Retrieving a String list from Apex get function with Javascript in VF

Is there a way to return a JavaScript array of Strings from Apex? Or is there a datatype in Javascript I need to use for an Apex List<String>?

 

 

A simple example of what I'd like to do:

 

Apex function:

 

public List<String> getStringList(){

 

    List<String> example =  {"email@gmail.com","email@yahoo.com","email@mac.com"};

 

   return example;

 

}

 

Javascript function in VisualForce

 

var stringList;

function() {

 

stringList = {!String};

document.writeln(stringList[0]);

 

}

 

 

StephenJacobGoldbergStephenJacobGoldberg

Not sure if this is what you are looking for, but you can do this ...

 

 

 

APEX CLASS
public List<String> getStringList(){

     List<String> example =  {"email@gmail.com","email@yahoo.com","email@mac.com"};

    return example;

}

VFORCE PAGE

<apex:dataTable value="{!StringList}" var="sl" >
<apex:column headerValue="email address" value="{!sl}"/>
</apex:dataTable>

 

 

GramGram

Thanks for the suggestion but that wouldn't work for my problem. Sorry, if the example I gave suggested that I was trying to output the strings into a datatable. I'm trying to bring up several custom fields from a list of accounts to add to an infowindow inside a google maps api. Currently, I return one long string and split it up into substrings of the data I need. I'd like a way to access an array or list of those strings or any other datatypes. Is there a way to do that?