thymeleaf 2.x
<a th:attr="data-bind=${priceBlock.key}" href="javascript:void(0);"
th:οnclick="'changeSimpleCondition(\'priceBlock\',\'' + ${priceBlock.key} + '\')'"
th:text="${priceBlock.value.min < 0} ? (${priceBlock.value.max} + '元以下' ):
(${priceBlock.value.max < 0} ? ${priceBlock.value.min} + '元以上' :
${priceBlock.value.min} + '-' + ${priceBlock.value.max} + '元')">
</a>
然而在版本升级到3.x以后会出现以下异常:
Only variable expressions returning numbers or booleans are allowed in this context
解决方案:
thymeleaf 3.0
<tr th:each="priceBlock : ${priceBlocks}">
<a th:attr="data-bind=${priceBlock.key}" href="javascript:void(0);"
th:οnclick="changeSimpleCondition('priceBlock',[[${priceBlock.key}]]);"
th:text="${priceBlock.value.min < 0} ? (${priceBlock.value.max} + '元以下' ):
(${priceBlock.value.max < 0} ? ${priceBlock.value.min} + '元以上' :
${priceBlock.value.min} + '-' + ${priceBlock.value.max} + '元')">
</a>