Python递归实现easyui的代码教程
程序员文章站
2022-04-24 21:40:12
表结构:
DOMAIN_ID N
INTEGER --ID
NAME N...
表结构:
DOMAIN_ID N INTEGER --ID NAME N VARCHAR2(128) --名称 PAR_DOMAIN_ID N INTEGER --父子关联ID
Html代码:
<input class="easyui-combotree" style="width:200px" id="topDetail" name="topDetail" data-options="editable:true" >
Javascript代码:
$.ajax({ type:'post', url: "get_comb_tree?domainID={{ domainID }}", dataType:'json', success: function(data){ for(var i = 0; i < data.length; i ++){ if(data[i].checked == "true"){ $("#topDetail").combotree("setValue",data[i].id); break; } } $('#topDetail').combotree('loadData', data); } });
Python代码:
def recursion_tree_data(par_domainId): """ @说明:递归,按照Easyui ComboTree数据格式,生成对应的json数据 @param par_domainId: 子ID """ tree_list = [] c = connections[gdata.dn].cursor() topoly_sql = """ SELECT T.DOMAIN_ID,T.NAME,T.PAR_DOMAIN_ID,T.PIC_PATH FROM V2_TOPLOGY_DOMAIN T where nvl(T.PAR_DOMAIN_ID,0) = %s """ % par_domainId topoly = dbquery(c ,topoly_sql) for t in topoly: children_map = {} domain_id = t['DOMAIN_ID'] par_domain_id = t['PAR_DOMAIN_ID'] name = t['NAME'] children_map['id'] = domain_id children_map['text'] = name children_map['state'] = 'closed' children_map['iconCls'] = 'icon-domain' # 这里开始递归子节点 children_map['children'] = recursion_tree_data(domain_id) tree_list.append(children_map) return tree_list def get_comb_tree(request, response=None, render=None): """ @说明:调用递归算法生成树列表转为json返回到页面 """ domainId = request.REQUEST.get("domainID","0") data = recursion_tree_data(domainId) return HttpResponse(content_type = 'application/json; charset=utf-8' , content = json.write(data))
上一篇: NVIDIA 510.06全新驱动发布:不再支持Kepler架构
下一篇: 知道!那个人是我