本文介绍了Thymeleaf:传递javascript参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基本的 SpringBoot 应用程序.使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件.我想将 POJO 的属性传递给 javascript 函数:
I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I want to pass an attribute of a POJO to a javascript function:
<tr th:each="company: ${companies}" > <td class="col_actions"> <a th:href="@{/company/edit/{id}(id=${company.id})}" style="color:#808080; margin-right: 10px;"> <i class="fa fa-pencil-square-o" aria-hidden="true"></i> </a> <a href="#" style="color:#808080; text-align: center;" onclick="javascript:confirmDelete ({id}(id=${company.id}));"> <i class="fa fa-times" aria-hidden="true" ></i> </a> </td> </tr>但是我得到一个错误:Uncaught SyntaxError: missing ) after argument list
推荐答案问题出在anchor上,如果confirmDelete()函数需要字符串id,请试试这个方法
The problem came from anchor, so please try this one if the confirmDelete() function require a string id
th:onclick="'javascript:confirmDelete(\'' + ${company.id} + '\');'"如果它需要一个号码 id
And if it need a number id
th:onclick="'javascript:confirmDelete(' + ${company.id} + ');'"更多推荐
Thymeleaf:传递javascript参数
发布评论