1

I have a Map fetched from a database and I want to use the data to populate Select box. The Map is added to the model using sellerCodeList

In Spring it is simple:

<form:select path="orderDetails[0].SellerItemCode" items="${sellerCodeList}">
</form:select>

But I want to use the same in a Jquery function which builds up my select box. (Reason: I have a table with dynamic rows and each row has a select box as one of the element)

When I use the following I start getting error/exception

$("#poFields").append('<tr valign="top"><td>
<form:select path="orderDetails['+rowNum+'].SellerItemCode" items="${sellerCodeList}">
</form:select>');

This throws an exception

I see on SO that there is a way to iterate over the sellerCodeList and feed to options as per the following Dropdown link from SO

I am not good with JSON stuff though ;-)

Can someone please help

Community
  • 1
  • 1
Saurabh Singhal
  • 271
  • 1
  • 5
  • 18

1 Answers1

1

You'll need to "print" your items into JS so that your JS code has access to them. Something like this:

<script>
    var sellerCodes = {};
    <c:forEach items="${sellerCodeList}" var="entry">
        sellerCodes['${entry.key}'] = '${entry.value}';
    </c:forEach>
    // you can now use sellerCodes in your JS code as a map.
</script>
SergeyB
  • 9,051
  • 3
  • 33
  • 46