Quiero llamar a la función javascript en 'th: if'. Este es mi código.
<li th:each="dto, stat : ${list}" th:if="${stat.count>10}"> <span th:if="'javascript:isNew('+${dto.regDts}+');'">blah blah</span> </li> ... <script th:inline="javascript"> function isNew(date) { if (...) { return true; } return false; } </script>pero no llama a isNew().
así que cuando escribí así...
<span th:if="isNew(${dto.regDts});">blah blah</span>tengo un error
¿Cómo puedo llamar a la función javascript en "th: if"?
Thymeleaf genera HTML en el servidor y lo pasa al navegador. En ese momento, Thymeleaf ya no está "activo". JavaScript se ejecuta en el navegador usando el HTML que ha generado Thymeleaf. Entonces es imposible hacer lo que quieres así.
La solución más sencilla es agregar un método o propiedad adicional en el objeto Java que se utiliza. Suponga que agrega un método isNew() en su dto, luego puede hacer:
<li th:each="dto, stat : ${list}" th:if="${stat.count>10}"> <span th:if="${dto.new}">blah blah</span> </li>