2015-09-30 48 views
2

模型圖(字符串,整數),該地圖在像複選框頁面上顯示:提交地圖<字符串,整數> Thymeleaf

<ul> 
    <li th:each="item : ${map}"> 
    <input type="checkbox" th:checked="${item.value} == 1" th:id="${item.key}"/> 
    <label th:for="${item.key}" th:text="${item.key}"/> 
    </li> 
</ul> 

我應該如何提交複選框狀態變化?

+0

我相信你需要一個包裝對象來保存提交的數據,就像這樣:http://stackoverflow.com/a/36522177/3416320 – bpgriner

回答

1

如果您正在使用Spring MVC爲您的應用程序和Thymeleaf爲您的視圖引擎請查看動態表單本節,並與他們合作:

http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#dynamic-fields

基本上你想要做的是有一個這個對象將會有一個Map作爲其中的一個變量,然後這個變量會將所有輸入綁定到控制器上。

例如

public class MyObject { 
    Map<String, Integer> myMap; 

// getters and setters 
} 
+0

好像有用的信息,但它並不清楚我如何在我的情況下使用它。 – SKS

+0

爲了理解信息的流向,你應該仔細研究你的框架MVC。瞭解如何在視圖和控制器之間傳遞數據對於理解解決方案至關重要,並且沒有更簡單的方法來編寫/演示它。 – Aeseir

相關問題