主题:后台传值到页面为{

ard_zl 2019年10月29日 32

java 后台代码:

{"assessId":"d5c6a4cc-f4c7-408b-bef6-8736c42df164","targetList":[{"name":"TotalAppointment","value":"56"},{"name":"CheckUpAppointment","value":"56"},{"name":"CheckOutAppointment","value":"56"},{"name":"TreatAppointment","value":"56"},{"name":"OutOperationAppointment","value":"56"},{"name":"InHospitalRecord","value":"56"},{"name":"ResisterAppointment","value":"56"},{"name":"TotalChange","value":"56"},{"name":"AllPatientFeed","value":"56"},{"name":"FollowUpPatient","value":"56"},{"name":"SignUpPatient","value":"56"},{"name":"AllCoefficient","value":"56"}]}

model.addAttribute("targetData",targetData);

页面接收  js中写的代码

用隐藏文本域 <input type="hidden" id="targetData" value="${targetData}"/>

var targetData = $("#targetData").val();

targetDataObj =JSON.parse(targetData);

alert(targetData );弹出为{

yingcait 2019年10月29日

在标签属性里传json变量需要谨慎,因为json包含了"}",容易与占位符混合导致解析出错,因此得使用"\"符号,如<#input value="${ {age:25\} }" />
http://ibeetl.com/guide/#/beetl/basic?id=html%E6%A0%87%E7%AD%BE

我也没看懂,标签属性中如何绑定json数据格式。

不过你这情况,可以直接在JavaScript中输出:

var targetDataObj =JSON.parse(${targetData});

ard_zl 2019年10月29日

好谢谢,已经解决,的确是字符窜问题,在页面传过来的字符窜,是双引号,导致页面解析报错