grails,groovy无限树递归
发布时间:2020-12-14 16:47:07 所属栏目:大数据 来源:网络整理
导读:def treegrid(){ def res=injectNews(0) render res as JSON } def injectNews={pid- def mkInstance def result=[] if(pid==0){//判断是不是为0如果为0就是上一个方法传过来的如果不是就是递归 mkInstance=WXslwMk01.executeQuery("from WXslwMk01 where (n
def treegrid(){ def res=injectNews(0) render res as JSON } def injectNews={pid-> def mkInstance def result=[] if(pid==0){//判断是不是为0如果为0就是上一个方法传过来的如果不是就是递归 mkInstance=WXslwMk01.executeQuery("from WXslwMk01 where (name='新闻资讯' or name='基层党建' or name='弘扬正能量' or name='社区文化' or name='就业服务' or name='居民委员会' or name='丝路话语' or name='志愿者风采') and sfjy=false ") }else{ mkInstance=WXslwMk01.findAllByParentAndSfjy(pid,false) } mkInstance.each {mk-> def tMap=[:]; def tMap1=[:]; def tFind=WXslwMk01.findAllByParentAndSfjy(mk?.id,false)//查询判断还没有下一级 /* * 重新定义map键, * 不定义可能跟jquery里的关键字冲突发生未知的错误 *TypeError: row is null row.state="open"; * too much recursion; * */ tMap1.idname=mk?.id tMap1.pId=mk?.parent tMap1.mkName=mk?.name tMap1.sfjy=mk?.sfjy tMap.putAll(tMap1); tMap.state=tFind?"closed":"open";//如果有就表示是父级他的状态就是closed不然就是子级状态就是open if(tFind){//判断有没有下一级了就了就继续递归 tMap.children=injectNews(mk?.id); } result.add(tMap); } return result; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |