Dynamic select options.

Hi,

I need some help in how to code dynamic select options based on the ‘model’ provided by the server.

I have the basics working for a single ‘username’ see below.
Note: There would be a test around the lightboxsections to see if the dynamicpart was needed at all.

But I am struggling when instead of a ‘username’ the model provides a list of ‘usernames’.

I can see how I can use JSTL to loop round the list.

<c:foreach var=”entry” items=”user.list”>

</c:foreach>

I am struggling to understand the Javascript to create the correct contents inside the loop taking into account the need for commas between the ‘options’.

[code]

var dynamicpart;

var dynamicpart = {key:“Username”,label:"${user.username}"};

var lightboxsections = [
{name:“text”, height:150, map_to:“text”, type:“textarea” , focus:true},
{name:“type”, height:21, map_to:“typeofevent”, type:“select”, options:[
{key:“A”, label:“A”} ,
dynamicpart
]},
{name:“time”, height:72, type:“time”, map_to:“auto”}
];

[\code]

Thanks for any help.

Something like next can be used

var data = []; <c:foreach var=”entry” items=”user.list”> data.push({key:"%some%", label:"%some%"} ,) </c:foreach> .... {name:"type", height:21, map_to:"typeofevent", type:"select", options:data},

Thanks I tried this but I could not get the " ,) " to compile.

Hello,

I believe this was mistype, try

var data = []; <c:foreach var=”entry” items=”user.list”> data.push({key:"%some%", label:"%some%"}); </c:foreach> .... {name:"type", height:21, map_to:"typeofevent", type:"select", options:data},
Best regards,
Ilya

Thanks should have spotted that.