后台查询到的List分装成combotree所需的数据源

来源:互联网 发布:three.js 360度全景 编辑:程序博客网 时间:2024/06/18 06:53

数据展示

package com.hopechart.configrec.entity;public class LineTree {    private String key;    private String value;    public String getKey() {        return key;    }    public void setKey(String key) {        this.key = key;    }    public String getValue() {        return value;    }    public void setValue(String value) {        this.value = value;    }}
public void allLine(HttpServletRequest request,HttpServletResponse response) throws Exception {         String str = "";         List<String>allLines=configRecService.queryConfigRecAllLine();         List<LineTree> tree = new ArrayList<LineTree>();         for (int i = 0; i < allLines.size(); i++) {             LineTree combo = new LineTree();             combo.setKey("0"+i);             combo.setValue(allLines.get(i));             tree.add(combo);        }        List<HashMap<String, Object>> roots = new ArrayList<HashMap<String,Object>>();        HashMap<String, Object> root = new HashMap<String, Object>();        root.put("id", "");        root.put("text", "全部");        root.put("iconCls", "");        HashMap<String, Object> group1 = new HashMap<String, Object>();        group1.put("id", "0");        group1.put("text", "车辆档案设置");        group1.put("iconCls", "");        List<HashMap<String, Object>> list = new ArrayList<HashMap<String,Object>>();        for (LineTree data : tree) {            HashMap<String, Object> type = new HashMap<String, Object>();            type.put("id", data.getKey());            type.put("text", data.getValue());            type.put("iconCls", "");            list.add(type);            }        group1.put("children", list);        List<HashMap<String, Object>> group = new ArrayList<HashMap<String, Object>>();        group.add(group1);        root.put("children", group);        roots.add(root);         str = JSONArray.fromObject(roots).toString();         WebUtils.write(response, str, "html");    }
0 0
原创粉丝点击