[英]Conditional inline formatting with thymeleaf attributes
我想通过比较两个属性来有条件地设置元素的样式。
th:each="客户:${客户}"
如果这两个参数相等,我想更改按钮的背景。 我正在使用 thymeleaf 的内联样式。
th:style="${param.customerID == customer.id ? 'background-color:green' : 'background-color:red'}"
但即使两个 arguments 相等,条件的结果也始终为假。
<div class="user-list">
<div class="active-btn-group" id="active-button-group" th:each=" customer : ${customers}">
<p th:text="${param.customerID}">Test</p>
<p th:text="${customer.id}">Test</p>
<button th:id="${customer.id}" th:style="${param.customerID == customer.id ? 'background-color:green' : 'background-color:red'}">
</button>
</div>
</div>
我应该如何更改 about 内联格式表达式?
我认为存在类型转换问题。 你会尝试像下面这样th:style="${#strings.equals(#strings.toString(param.customerID), #strings.toString(customer.id))?'background-color:green': 'background-color:red' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.