2016-07-19 38 views
1

我在JSP文件中的一個片段如下thymeleaf設定值ATTR輸入標籤

<c:forEach var="question" items="${questionList }"> 
    <p>{{ question.question }}</p> 

    <c:forEach var="answer" items="${question.answerList }"> 
     <input type="radio" name="${question.id }" id="${answer.id }" value="${answer.sequence }"> 
     <label for="${answer.id }">${answer.answer }</label> 
    </c:forEach> 

</c:forEach> 

現在我用thymeleaf模板,我不知道如何實現它在百里香。尤其是,我卻不知道怎麼去name ATTR爲input

<div th:each="answer : ${question.answerList }"> 
    <input type="radio" name="how to do?" id="how to do?" value="how to do?" th:value="${answer.sequence}"> 
    <label th:text="${ans.answer}"></label> 
</div> 

回答

0

您可以th:with嘗試在thymeleaf局部變量工作,

<div th:with="questionObj=${questionList}"> 
    <div th:each="answer: ${questionObj}"> 
     <input type="radio" th:name="${questionObj.id}" 
       th:id="${answer.id}" th:value="${answer.sequence}"> 
     <label th:text="${answer.answer}"></label> 
    </div> 
</div> 

參見:Local Variables

+0

謝謝,但現在我已經從我的項目中刪除了thymeleaf並添加了jsp。 –