1、通过下了方式获取(无法取到值)
var list=[[${currMorList}]] var list='[[${currMorList}]] '
2、通过隐藏域获取
<div><input id="currMorList" th:type="hidden" th:value="${currMorList}"></div><script> layui.use(['layer', 'miniTab','echarts','carousel'], function () { var curr=$('#currMorList').val var curr=document.getElementById('currMorList').value }) </script>
3、解析获取到的list
通过以下方式解析时候报错: $.each(curr,function(index,item){ var card11=''+item.Name+ ' | '+item.Dept+ ' | '+item.others+ ' |
'; $('#card1').append(card11); }); Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [{"endDate":"2022-03-26 17:00:00","Dept":"办公室","Name":"王五","startDate":"2022-03-24 08:00:00","others":"Tue Jun 03 00:00:00 CST 2138到Tue Jun 03 00:00:00 CST 2138"},{"endDate":"2022-03-29 12:00:00","Dept":"科室","Name":"张三","startDate":"2022-03-25 08:00:00","others":"Tue Jun 03 00:00:00 CST 2138到Tue Jun 03 00:00:00 CST 2138"}] at n (VM363 layui.js:2:41840) at Function.each (VM363 layui.js:2:58719) var cmList=JSON.parse(document.getElementById('currMorList').value);
4、对应的controller
@GetMapping("/getList") public String main(ModelMap model) throws ParseException { model.addAttribute("currMorList",JSONUtil.parse(currMorList));return "index"; }