Java返回 easyui树,java 结构easyui tree 的返回值json

java 构造easyui tree 的返回值json

public @ResponseBody List formatTree(HttpServletRequest request,HttpServletResponse response) throws Exception {

List cityList =cityTreeService.getCityTreeList();

Map map = new HashMap();

List treelist = new ArrayList(); //返回json

map.put("id", cityList.get(0).getId());  //父节点

map.put("text", cityList.get(0).getName());

//map.put("parentid", cityList.get(0).getParentid());

List children = new ArrayList();

for (int i=1; i

CityName e = cityList.get(i);

if (cityList != null && cityList.size() > 0){

if(e.getParentid().equals(cityList.get(0).getId())){

Map childmap = new HashMap();

childmap.put("id", e.getId());

childmap.put("text", e.getName());

childmap.put("sort", e.getSort());

childmap.put("slevel", "市");

childmap.put("updatedate",new DateUtil().getDateStrCompact(new DateUtil().addDate(e.getUpdatetime(), 2),"yyyy-MM-dd"));

//childmap.put("parentid", e.getParentid());

List childrens = new ArrayList();  //添加子节点的孩子节点

for (int j=1; j

CityName c = cityList.get(j);

if(c.getParentid().equals(e.getId())){

Map childmaps = new HashMap();

childmaps.put("id", c.getId());

childmaps.put("text", c.getName());

childmaps.put("sort", c.getSort());

childmaps.put("slevel", "区镇");

childmaps.put("updatedate",new DateUtil().getDateStrCompact(new DateUtil().addDate(c.getUpdatetime(), 2),"yyyy-MM-dd"));

//childmaps.put("parentid", c.getParentid());

childrens.add(childmaps);

}

}

if(childrens.size()>0){

childmap.put("state","closed"); //state:节点状态, 'open' 或 'closed',默认是 'open'。

childmap.put("children", childrens);

}

children.add(childmap);

}

}

}

map.put("children", children);

treelist.add(map);

return treelist;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值