温馨提示:本文翻译自stackoverflow.com,查看原文请点击:spring boot - Pass a List to Javascript function in Thymeleaf
spring-boot Thymeleaf

spring boot - 将列表传递给Thymeleaf中的Javascript函数

发布于 2020-03-29 21:42:10

我已经看到了几个将单个参数发送到JavaScript函数的示例,但没有列表的示例。

当我尝试传递列表时,它起一个大字符串的作用。这就是我所拥有的:

<select id="namespace" name="namespace"
        th:responseList="${responseList}"
        th:onchange="javascript:print(this.getAttribute('responseList'));">
        <option value="">Select Source Namespace</option>
        <option th:each="item : ${responseList}"
            th:value="${item.namespace}"
            th:text="${item.namespace}"></option>
</select>

function print(responseList) {
    console.log(responseList);
}

查看更多

提问者
Faraz
被浏览
118
A.khalifa 2020-01-31 18:34

尝试这个

<script th:inline="javascript">
    var list = [[${responseList}]]; 
    console.log(list );
</script>

希望为您工作