我正在使用 Thymeleaf 和 Spring Boot。 我有一个使用这些脚本创建的表:http://bootstrap-table.wenzhixin.net.cn/
然后我添加了一个javascript:
<script th:inline="javascript">
/*<![CDATA[*/
$(function() {
$("#list").on('click-row.bs.table',
function(e, row, $element, field) {
window.location = /*[[@{/url/}]]*/+row.id;
});
});
/*]]>*/
</script>
如您所见,我添加了 /*[[@{/url/}]]*/
来生成正确的 url,但我必须将它与 id 连接起来。
问题是它从不将 id 附加到 url.. 为什么? 我该如何解决?
最佳答案
您可以先将 Thymeleaf Java 对象放入某个 javascript 变量中,然后像通常在 javascript 中那样使用它。
var url = /*[[@{/url/}]]*/
window.location = url + row.id;
来自 12.2 Script inlining (JavaScript and Dart) documentation :
Thymeleaf will execute the expression and insert the result, but it will also remove all the code in the line after the inline expression itself (the part that is executed when displayed statically).
关于javascript - 如何将整数附加到 url 脚本内联 thymeleaf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47692798/