在JS一个插件上需要使用数组集合对象,后台拼接好数据之后,前端JS获取之后显示的是有转义码的
Character | Entity Number | Entity Name | Description |
---|---|---|---|
" | " | " | quotation mark |
’ | ' | ' (does not work in IE) | apostrophe |
& | & | & | ampersand |
导致后台返回的对象在JS显示错误,需要特殊处理下。
插件所需的数据结构:
//后台组装代码
JSONArray jsonArray = new JSONArray();
for (RugroupProduct temp:rugroupProducts){
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",temp.getProductCode());
jsonObject.put("value",temp.getProductName());
jsonArray.add(jsonObject);
}
//前台需要的格式
var foo = [
{'id':'1',
'value':'v'
},{'id':'2',
'value':'v2'
}
];
后端:URLEncoder.encode(jsonArray.toJSONString(),“UTF-8”)
前端:$ .parseJSON(decodeURIComponent(’[[${recomm}]]’));
这样就可以把后台接受到的参数直接传给插件对象进行展示了