zTree如何更换url地址?

一号男嘉宾 发布于 2013/04/17 14:44
阅读 1K+
收藏 0

@ztree

如题,比如我有一个下拉列表,我希望根据用户的选择,显示不同的树,请问如何动态修改ztree获取数据的url?

加载中
0
小xu
小xu

三个页签菜单:

<ul>
        <li style=""><p:commandLink styleClass="tabMenu" onclick="change_tree('business');">
         <img src="../../resources/images/common/tabicon_02.png"/><span>业务</span></p:commandLink></li>
        <li ><p:commandLink styleClass="tabMenu select" onclick="change_tree('department');">
         <img src="../../resources/images/common/tabicon_03.png" /><span>部门</span></p:commandLink></li>
        <li><p:commandLink styleClass="tabMenu" onclick="change_tree('element');">
         <img src="../../resources/images/common/tabicon_04.png" /><span>要素</span></p:commandLink></li>
       </ul>

function change_tree(element){
     if(element=="department"){
      var sql = "select y.org_code as id,y.sup_org_code as pid,y.org_cname_s as name,'0' as open ,'1' as nocheck,'1' as isParent,decode(ORG_PROP,'1','../../resources/images/tree/tabicon_home.png','3','../../resources/images/tree/tree_4.png') as icon,y.org_cname_s from yupeng_org y ";
     }
     if(element=="business"){
      var sql = "select d.catalog_xscode as id,d.sup_catalog_no as pid,d.catalog_name as name,'0' as open ,'1' as nocheck,decode(CATALOG_PROP, '4', '0', '1') as isParent,decode(CATALOG_PROP,'1','../../resources/images/tree/tabicon_home.png','4','../../resources/images/tree/tree_4.png','2','../../resources/images/tree/tree_lup_n.png') as icon from catalog_data_res d where d.CATALOG_PROP != 0 order by d.catalog_no ";
     }
     if(element=="element"){
      var sql = "select y.org_code as id,y.sup_org_code as pid,y.org_cname_s as name,y.org_cname_s from yupeng_org y ";
     }
     create_tree(sql);
    }

 

function create_tree(sql){
     var settings = {
      check : {
       enable : true,
       
      },
      data : {
       simpleData : {
       enable : true
      }
      },
      callback : {
       beforeClick : dcplat.tree.beforeClick,
       onRightClick : onRightClick
      }
      };
      dcplat.tree.commonTree("treeDemo","dcplat_ds", sql, settings);    }

 

小xu
小xu
封装生成树的脚本啊,sql有了自己生成树啊!
一号男嘉宾
一号男嘉宾
dcplat.tree.commonTree
一号男嘉宾
一号男嘉宾
哥们,你这个哪里来的?
0
zTree
zTree

不错,如果后台能一个接口实现,那么就不需要前台操作了; 

如果想在前台更换,那么直接让你的 setting.async.url = function() {.....  return url}  这样就行了, 每次异步加载时,你都可以根据 父节点的 id 确定 后台获取地址的 url;

如果你是每次根据不同的情况更换 树上的全部节点,那么只要是 树初始化之后,每次只需要修改 zTreeObj.setting.async.url 的值,然后执行 reAsyncChildNodes 方法让根节点重新加载也可以。。

总之,条条大路通罗马,选择最适合自己的就是了

一号男嘉宾
一号男嘉宾
我试一下,谢谢你的回复。
返回顶部
顶部