thymeleaf - 脚本和 th:block

WEB*_*TER 0 javascript thymeleaf

)有没有办法在“script”标签内使用“th:block”标签?像这样的东西:

<script type="text/javascript">
    <th:block>
        var test = 1;
    </th:block>
</script>
Run Code Online (Sandbox Code Playgroud)

Pau*_*Pau 5

你应该使用 attribute th:inline="javascript",然后你可以使用 ath:block但不能在标签中使用,你必须使用如下语法:

<script th:inline="javascript">
    [#th:block th:each="item : ${items}"]
      - [#th:block th:utext="${item}" /]
    [/th:block]
</script>
Run Code Online (Sandbox Code Playgroud)