【发布时间】:2020-09-02 23:34:12
【问题描述】:
我想将 Thymleaf 变量传递给 javascript 函数。我的百里香叶是这样的
<a class="cat-title" th:onclick="|fetchProduct('${category.categoryId}','${businessId}')|">
<p th:text="${category.name}"></a>
而我的javascript代码是这样的
function fetchProduct(businessId,categoryId) {
var productUrl = '/webstore/business/' + businessId + '/category/' + categoryId + '/products';
............
............
}
但是当我加载页面时出现此错误
引起:org.thymeleaf.exceptions.TemplateProcessingException:仅 允许返回数字或布尔值的变量表达式 上下文中,任何其他数据类型在此上下文中均不受信任 表达式,包括字符串或任何其他可能的对象 呈现为文本文字。
这个错误的原因是什么?
【问题讨论】:
-
这能回答你的问题吗? Add Variable inside th:onsubmit thymeleaf
标签: javascript spring-boot thymeleaf