private JSONArray queryTree(Long parentId, List<Long> grantedList) {
JSONArray array = new JSONArray();
List<City> cityList = cityService.loadByParentId(parentId);
for(City city : cityList) {
JSONObject obj = new JSONObject();
obj.put("text", city.getCityName());
obj.put("cityId", city.getCityId());
obj.put("iconCls", "tree_node_noicon");
if(city.getLevelNum() < 3) {
obj.put("expanded", true);
}
obj.put("checked", grantedList.contains(city.getCityId()));
JSONArray children = queryTree(city.getCityId(), grantedList);
if(children.length() == 0) {
obj.put("leaf", true);
} else {
obj.put("children", children);
}
array.put(obj);
}
return array;
}
递归算法
最新推荐文章于 2023-06-17 20:58:01 发布