列表包含2個元素[0],[1]。Thymeleaf嵌套列表/ ArrayList - 獲取所有元素的總大小
元素列表 - [0]具有嵌套的ArrayList五行 [0] [1],[2],[3],[4],[5]
[1]有4種元素 [0],[1],[2],[3],[4]
我怎樣才能獲得總長度/大小在Thymeleaf,即9?如果可能的話,我需要在任何循環之外使用它來保存一個臨時值。
這使我想到下一個問題,我如何在Thymeleaf中使用.size而不是遍歷數據結構來保存本地自定義變量?我準備好寫一個循環來獲取這個.size,如果需要的話,但我想將它存儲在一個局部變量中,我可能稍後在另一個循環中重用它!
實施例:
<div th:each="test : ${testList}">
<div th:each="testItem : ${test.subArrayList}">
<div th:each="testItemSub : ${testItem}">
<span> Get total size of "${testItemSub.name}" and store in a variable</span>
</div>
</div>
</div>
隨着Thymeleaf有更新版本,您可以只使用$ {#lists.size(名單)}爲大小 – 2016-03-08 16:49:52