欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python递归实现easyui的代码教程

程序员文章站 2022-09-25 12:36:49
表结构: 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))