[{"id":1,"text":"ssssss","pid":0,"state":"closed"},
{"id":2,"text":"aaaaaaa","pid":0,"state":"closed"},
{"id":5,"text":"dddddddd","pid":0,"state":"closed"},
{"id":10,"text":"lllllll","pid":0,"state":"closed"},
{"id":15,"text":"eeeeeeee","pid":0,"state":"closed"},]
上面是后台拿到的数据,前台传值的时候报错
<!--这是页面上的代码 --> <script type="text/javascript"> $(function(){ debugger; $('#areaName').combotree({ url:'${pageContext.request.contextPath}/sys/network/getComBoTree'}); });</script>
<input class="easyui-combotree" id="areaName" style="width:170px;" >//后台代码
@RequestMapping(value = "/getComBoTree", method = RequestMethod.POST)
public @ResponseBody JsonResponse getComBoTree(@RequestParam(value ="id", required = false) String id) {
if(id!=null){
log.debug("param map={}", id);
//封装查询条件
PageDomain<Network> pd = new PageDomain<Network>();
pd.addWhereObjList(new WhereObj("PID", "=", id));
pd.setOrderBy("ID asc ");
List<Network> resultsList = new ArrayList<Network>();
List<ComBoTree> treeList = new ArrayList<ComBoTree>();
try {
//查询结果集
List<Network> networkList = netWorkBmo.findDataByCondition(pd);
resultsList.addAll(networkList);
log.debug("resultsList={}", JsonUtil.toString(resultsList));
//遍历 结果集 做成 json 格式
for(Iterator iterator = resultsList.iterator();iterator.hasNext();){
Network ntwk = (Network) iterator.next();
ComBoTree t = new ComBoTree();
t.setId(ntwk.getId());
t.setText(ntwk.getName());
t.setParentId(ntwk.getPid());
if(loadNetworkByChildren(id).size()>0){
t.setState("closed");
}else{
t.setState("open");
}
/* Map<String,Object> map = new HashMap<String,Object>();
map.put("ParentId", ntwk.getPid());
t.setAttributes(map);*/
treeList.add(t);
}
log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>treeList={}", JsonUtil.toString(treeList));
return super.successed(treeList);
//model.addAttribute("networkTerminalPm", networkTerminalPm);
} catch (BusinessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
id="0";
getComBoTree(id);
}
return null;
}
public List<Network> loadNetworkByChildren(String id) {
log.debug("param map={}", id);
PageDomain<Network> pd = new PageDomain<Network>();
pd.addWhereObjList(new WhereObj("PID", "=", id));
pd.setOrderBy("ID asc ");
List<Network> resultsList = new ArrayList<Network>();
log.debug("param map={}", JsonUtil.toString(resultsList));
try {
List<Network> networkList = netWorkBmo.findDataByCondition(pd);
resultsList.addAll(networkList);
log.debug("resultsList={}>>>>>>>>>>>>>>>>>>>>", JsonUtil.toString(resultsList));
} catch (BusinessException e) {
e.printStackTrace();
}
return resultsList;
}
使用递归方法不当。应该使用 @RequestMapping(value="/getComBoTree",method=RequestMethod.POST)
public@ResponseBodyJsonResponsegetComBoTree(@RequestParam(value="id",required=false,defaultValue="0")Stringid){}
请求方式
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。