Thymeleaf classappend 用于多个类 [英] Thymeleaf classappend for multiple classes
本文介绍了Thymeleaf classappend 用于多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用条件添加多个类.
I want to add multiple classes using condition.
<div th:classappend="x.isTrue ?'class1' " ></div>
我想要类似的东西
<div th:classappend="x.isTrue ?'class1' and "y.isTrue ?'class2'" ></div>
推荐答案
您可以使用 文字替换来实现这一点:
You can use literal substitutions to achieve this:
<div th:classappend="|${x.isTrue ? 'class1' : ''} ${y.isTrue ? 'class2' : ''}|"></div>
另一种方法是简单地用括号括起条件并将它们连接起来:
Another method is to simply wrap your conditions with brackets and concatenate them:
<div th:classappend="${(x.isTrue ? 'class1' : '') + (y.isTrue ? ' class2' : '')}"></div>
这篇关于Thymeleaf classappend 用于多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文