我正在将 Spring Boot 1 应用程序迁移到 Spring Boot 2。 在原始应用程序中,我看到很多这样的部分:
<script th:inline="javascript">
<th:block th:include="fragments/script :: actionsMenu-js"/>
$(document).ready(function() {
...
});
现在使用 Thymeleaf 3,即使在更改要插入的包含内容之后,这似乎也不再起作用:
<script th:inline="javascript">
<th:block th:insert="~{fragments/script :: actionsMenu-js}"/>
$(document).ready(function() {
...
});
该 block 未插入,Javascript 不正确,我得到:
messages:180 Uncaught SyntaxError: Unexpected token <
我可以编辑所有页面并将 block 放置在脚本之外,但我更喜欢需要较少重构的方法。
最佳答案
如果改用 TEXT 语法可以吗?
[# th:insert="~{fragments/script :: actionsMenu-js}" /]
关于javascript - 在 Javascript 中插入 Thymeleaf 片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57849498/