后端相关代码
@RequestMapping("/ztreeTest1")
public String ztreeTest1(Model model,HttpServletRequest request) throws JsonProcessingException {
List<Ztreetest> nodes=ztreetestService.findall();
model.addAttribute("nodes",nodes);
return"ztreetest1";
}
前端代码:
var list = [[${nodes}]];
var zNodes= eval(list);
$(function () {
$.fn.zTree.init($("#treeTest"), setting, zNodes);
});
然后再前端可以出现错误
ztreeTest1:66 Uncaught ReferenceError: Ztreetest is not defined,
var list = [Ztreetest(id=1, pid=0, name=电视机, open=false, checked=false), Ztreetest(id=2, pid=1, name=超薄电视, open=false, checked=false), Ztreetest(id=3, pid=1, name=全屏电视, open=false, checked=false), Ztreetest(id=4, pid=1, name=高清电视, open=false, checked=false), Ztreetest(id=5, pid=0, name=空调, open=false, checked=false), Ztreetest(id=6, pid=5, name=空调挂机, open=false, checked=false), Ztreetest(id=7, pid=5, name=空调柜式, open=false, checked=false)];
希望大神指点