- 下拉框选项为层级为2的树
List<JSONObject> resObject = new LinkedList<>();
for(Dict dict : dictList){
JSONObject parentObject = new JSONObject();
parentObject.put("name", dict.getName());
parentObject.put("value", dict.getValue());
List<JSONObject> childListObject = new LinkedList<>();
for(Catalog catalog : catalogList){
JSONObject childObject = new JSONObject();
if(catalog.getCatalogType().equals(dict.getValue())){
childObject.put("name", catalog.getName());
childObject.put("value", catalog.getCatalogValue());
childObject.put("children", null);
childListObject.add(childObject);
}
}
parentObject.put("children", childListObject);
resObject.add(parentObject);
}
- 将下拉框选项树的根节点改为分组
List<JSONObject> resObject = new LinkedList<>();
for(Dict dict : dictList){
JSONObject parentObject = new JSONObject();
parentObject.put("name", dict.getName());
parentObject.put("value", dict.getValue());
parentObject.put("type", "optgroup");
resObject.add(parentObject);
for(Catalog catalog : catalogList){
JSONObject childObject = new JSONObject();
if(catalog.getCatalogType().equals(dict.getValue())){
childObject.put("name", catalog.getName());
childObject.put("value", catalog.getCatalogValue());
childObject.put("children", null);
resObject.add(childObject);
}
}
}