Using Spring MVC and Thymeleaf, I am creating an html view with some javascript inside.
Inside the page, th: each is used with iterative values ββto give the button set a unique HTML identifier.
<td th:each="optionValue,iterStat : ${someObject.optionValues}"> <button class="btn btn-default" th:id="${'optionBtn_' + (iterStat.count - 1)}" th:text="${optionValue.toString()}" /> </td>
My problem occurs when trying to generate javascript that will use a jQuery link for each button id.
In the 'other' permission permission language, I would use the code:
<% for(var i = 0; i < someObject.optionValues.length; i++) { %> $('#optionBtn_<%- i %>').on("click", function() { doSomething('<%= someObject.optionValues[i] %>'); }); <% } %>
(the above may not be 100% syntactically correct, but I hope you understand what I'm trying to do using this style)
but in Thymeleaf, although I understand that I can use
th:inline="javascript"
to refer to individual elements of the model, I donβt see how I can use the appearance to generate several jQuery function call definitions in a script block.
Any ideas? (I can approach the problem completely wrong, so I'm open to new ideas on this front too)
source share