我已经看到了几个将单个参数发送到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);
}
尝试这个
<script th:inline="javascript">
var list = [[${responseList}]];
console.log(list );
</script>
希望为您工作
我编辑我的答案