javascript - 如何将整数附加到 url 脚本内联 thymeleaf?

标签 javascript twitter-bootstrap spring-boot thymeleaf bootstrap-table

我正在使用 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/

相关文章:

java - Spring-Boot 可执行文件-Jar NoSuchBeanDefinitionException

Spring 启动: Inject Bean into HttpServlet

java - 如何在 Spring Boot 测试中设置 servlet 上下文路径?

javascript - 中止在 Redux 中获取数据

javascript - 为什么我无法在 strophe js 中接收消息?

css - 如何在 bootstrap col-md-1 中滚动

html - LESS 和 CSS 导入——变得疯狂

css - 编辑 Bootstrap css 类

javascript - 使用 for 循环将数据从一个 Google 表格映射到另一个 Google 表格

javascript - 打印 HTML 表格中选定的行