vendredi 2 janvier 2015

Populating Select Box from Collection using jQuery


I'm very new to jQuery, and I'm attempting to populate a select box from a collection. Basically, I want to take the code below, where "statuses" is the collection and move it to jQuery:



<widget:select property="statusCode" styleId="STATUSCODELIST" labelKey="label.status">
<html:option value=""/>
<c:forEach var="status" items="${applicationScope.statuses}">
<html:option value="${status.key}"><c:out value="${status.key} - ${status.value}"/></html:option>
</c:forEach>
</widget:select>


I'm trying to figure out how to get "statuses" to work something like the numbers array in this sample:



var numbers = [ 1, 2, 3, 4, 5]
var list = $('#STATUSCODELIST')[0];
$.each(numbers, function(index, text) {
list.options[list.options.length] = new Option(index, text);
});


Thanks for any help.





Aucun commentaire:

Enregistrer un commentaire