Thymeleaf:附加到 html 元素/避免重复迭代
Thymeleaf: append to html element / avoiding repetitive iteration
我正在寻找一种使用 Thymeleaf 将 html 元素动态附加到其他 html 元素的方法。
考虑以下因素:
<ol class="ol1" />
<ol class="ol2" />
<ol class="ol3" />
<iterate th:each="model">
<!-- ol1.append(model.name) -->
<!-- ol2.append(model.type) -->
<!-- ol3.append(model.something) -->
</iterate>
我知道一个可能的解决方案是有 3 个循环,一个嵌套在每个 <ol>
标签中,如下所示:
<ol class="ol1">
<iterate th:each="model">
model.name
</iterate>
</ol>
<ol class="ol2">
<iterate th:each="model">
model.type
</iterate>
</ol>
<ol class="ol3">
<iterate th:each="model">
model.something
</iterate>
</ol>
上述解决方案对我来说效率太低。
那么,Thymeleaf 是否提供在这种情况下只执行一次迭代的功能?
抱歉,没有比这更简单或更有效的方法了。我开始考虑其他方法来完成这项工作,none 比您在问题中使用的三个循环要好。
我正在寻找一种使用 Thymeleaf 将 html 元素动态附加到其他 html 元素的方法。
考虑以下因素:
<ol class="ol1" />
<ol class="ol2" />
<ol class="ol3" />
<iterate th:each="model">
<!-- ol1.append(model.name) -->
<!-- ol2.append(model.type) -->
<!-- ol3.append(model.something) -->
</iterate>
我知道一个可能的解决方案是有 3 个循环,一个嵌套在每个 <ol>
标签中,如下所示:
<ol class="ol1">
<iterate th:each="model">
model.name
</iterate>
</ol>
<ol class="ol2">
<iterate th:each="model">
model.type
</iterate>
</ol>
<ol class="ol3">
<iterate th:each="model">
model.something
</iterate>
</ol>
上述解决方案对我来说效率太低。
那么,Thymeleaf 是否提供在这种情况下只执行一次迭代的功能?
抱歉,没有比这更简单或更有效的方法了。我开始考虑其他方法来完成这项工作,none 比您在问题中使用的三个循环要好。