提问人:Dean Thomas 提问时间:10/19/2023 更新时间:10/20/2023 访问量:30
使用 thymeleaf 循环的有序列表未连接
Ordered list using thymeleaf loop not connected
问:
很抱歉,如果我必须含糊其辞,因为我无法真正展示客户的要求。
我有一个堆叠的有序列表,其中显示了父项和子项的详细信息。在父部分和子部分之前,第一个项目和父子部分之后的更多项目显示不同的详细信息,但我必须将其放在同一个列表中。因此,我想要实现的是:
但我得到的是:
<ol type="a">
<li>Coffee</li> //item without child detail
<span class="widget-has-slot">{{the parent-child widget}}<br />
<pre>
<li th:each="parent : ${parentChildMap}"> //parent
//parent detail
<ol> //child list start
<li th:each="child : ${parent.value}"> //child
//child detail
</li> //child closing tag
</ol> //child list end
</li> //parent closing tag
<li>Water</li> //more item without child detail
<li>Beer</li>
</ol>
我尝试使用计数器增量,但它仍然显示相同的结果。 参考:
- https://travishorn.com/ordered-lists-in-html-a4621e17532b
- https://www.w3schools.com/cssref/pr_gen_counter-increment.php#gsc.tab=0&gsc.q=list
目前,我正在使用 3 个不同的 ol 和起始值。一个用于第一项,一个用于百里香叶部分,另一个在百里香叶之后,它向我展示了我想要的结果,但我知道这效率不高,因为当父项数量更改时,我需要更改起始值。
<ol type="a"> // first ol
<li>Coffee</li> //item without child detail
</ol>
<span class="widget-has-slot">{{the parent-child widget}}<br />
<pre>
<ol type="a" start="2"> //second ol
<li th:each="parent : ${parentChildMap}"> //parent
//parent detail
<ol> //child list start
<li th:each="child : ${parent.value}"> //child
//child detail
</li> //child closing tag
</ol> //child list end
</li> //parent closing tag
</ol>
<ol type="a" start="5"> //third ol
<li>Water</li> //more item without child detail
<li>Beer</li>
</ol>
如何在不手动更改起始值的情况下让它们工作?
答:
1赞
Metroids
10/20/2023
#1
使用 ,并动态计算起始时间。th:start
<ol type="a" th:start="${2 + #lists.size(parentChildMap)}">
评论
0赞
Dean Thomas
10/20/2023
谢谢你的建议,但只有父子 ol 在小部件内,所以第一个和第三个 ol 是普通的 html。我不认为我能把另一个列表变成百里香叶。
0赞
Metroids
10/20/2023
Thymeleaf 没有“小部件”的概念......所以我不太确定你的意思。为什么在其他两个部分中仅限于普通的html?
0赞
Dean Thomas
10/23/2023
客户和团队的大多数成员以某种方式将 thymeleaf 部件称为小部件,对不起,我受到了影响并在这里使用了它。我们正在处理的页面是生成一个pdf报告,用户可以在其中编辑模板,我们使用html作为模板。
评论