我正在尝试在javascript中使用thymeleaf。 当我使用th时,我的代码工作正常:每个都使用html
<table>
<tr th:each="theme : ${les_themes_1}">
<td th:text="${theme.id}">id</td>
</tr>
</table>
但是当我在脚本中使用forEach时,它会返回null
<script th:inline="javascript" >
/*<![CDATA[*/
/*[# th:each="theme : ${les_themes_1}"]*/
document.write(/*[[${theme}]]*/); //return null
document.write(/*[[${theme.id}]]*/); //not working
/*[/]*/
/*]]>*/
</script>
帮助PLZ!谢谢!
答案 0 :(得分:0)
这类问题历史悠久,一直追溯到JSP规范的早期阶段。关于JavaScript的一个关键要点是它 在浏览器中根据服务器端Java组件生成的输出执行 。这适用于JSP和Javascript,Velocity和Javascript,JSTL和其他自定义标签和Javascript,以及Thymeleaf和Javascript。在这种情况下,Thymeleaf模板在Javascript之前执行。
了解这一点,一个关键的故障排除策略是简单地查看和检查HTML&amp;您在运行时生成的Javascript源代码。