Easyui Tree扁平化数据不显示父节点的一种解决方法

使用SSM框架结合Easyui搭建一个简单CRUD表单时遇到无法设置父节点的问题,输出如下:

后台controller代码:

1 public List<Tree> queryname(){
2 List<Tree> list = treeService.queryname();
3 return list;

前台获得的list:

[{"id": 1, "name": "区人大党组"},
  {"id": 2, "name": "区政府"},
  {"id": 5, "_parentId": 1, "name": "区人大2"},
  {"id": 7, "_parentId": 2, "name": "区政府2"},
  {"id": 22, "name": "机关"},
  {"id": 23, "name": "机关"},
  {"id": 31, "_parentId": 22, "name": "机关伙房"}]

对比Easyui官方实例提供的JSON数据格式进行对比:

{"rows":[
      {"id":1,"name":"All Tasks","progress":60,"iconCls":"icon-ok"},
      {"id":2,"name":"Designing","progress":100,"_parentId":1,"state":"closed"},
      {"id":21,"name":"Database","persons":2,"progress":100,"_parentId":2},
      {"id":22,"name":"UML","persons":1,"progress":100,"_parentId":2},
      {"id":23,"name":"Export Document","persons":1,"progress":100,"_parentId":2},
      {"id":3,"name":"Coding","persons":2,"progress":80},
      {"id":4,"name":"Testing","persons":1,"progress":20}
  ]}

发现后台返回的List的确是JSON格式,但缺少了一个"rows":

要检测数据是否为JSON格式可以使用以下工具校验:https://www.bejson.com/

解决方法如下:

controller修改为:

1 public Map<String, List<Tree>> queryname(){
2 List<Tree> list = treeService.queryname();
3 Map<String, List<Tree>> map = new HashMap<String, List<Tree>>(); 
4 map.put("rows", list); 
5 return map;  

成功!

 

posted @ 2018-06-11 14:36  莆田神医  阅读(297)  评论(0编辑  收藏  举报