zTree加载无限极

/***********************前端css********************************/

<style>
.ztree *{
font-family:"微软雅黑";
font-size:14px;
}
.ztree li span.button.pIcon_ico_open{margin-right:2px; background: url('<%=basePath%>resources/app/images/pIcon.png') no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
.ztree li span.button.pIcon_ico_close{margin-right:2px; background: url('<%=basePath%>resources/app/images/pIcon.png') no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}

.ztree li span.button.subIcon_ico_open, .ztree li span.button.subIcon_ico_close{margin-right:2px; background: url('<%=basePath%>resources/app/images/subIcon.png') no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}

.ztree li span.button.pIcon_ico_docu{margin-right:2px; background: url('<%=basePath%>resources/app/images/pIcon.png') no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
.ztree li span.button.subIcon_ico_docu{margin-right:2px; background: url('<%=basePath%>resources/app/images/subIcon.png') no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
</style>

/********************************前端js**********************/

var setting;
var selectedTreeId="";
var treeObj;

$(document).ready(function(){

var url="<%=basePath %>v/uc/user/getJsonSort";
    $.getJSON(url, function (zNodes){
        zNodes = "["+zNodes+"]";
        treeObj = $.fn.zTree.init($("#treeDemo"), setting, eval('('+zNodes+')'));
    });
    var ajaxUrl = "";
    setting= {
            async: {
                enable: true,
                url:function(){
                    return ajaxUrl;
                }
            },
            view: {
                showIcon: showIconForTree
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick:loadList,
                beforeExpand: function(treeId, treeNode) {
                    ajaxUrl = "<%=basePath %>v/uc/user/getSubJsonSort?code="+treeNode.id;
                }
            }   
    };
function showIconForTree(treeId, treeNode) {
    return treeNode.level != 2;
};
function loadList(event, treeId, treeNode,clickFlag) {
    selectedTreeId = treeNode.id;
    $("#list").setGridParam({
            postData:{orgn:treeNode.id}
      }).trigger("reloadGrid");
};

});

/*************************************后台拼接json***********/

@RequestMapping("getJsonSort")
    @ResponseBody
    public String getJsonSort(String code){
        /*String basePath = SystemPropertyGetUtil.getResource("config").getString("system.url.base");
        String pIconPath=basePath+"resources/app/images/subIcon.png";*/
        StringBuilder sb = new StringBuilder();
        List<SMTableZZJG> topList = orgnService.getTopOrgn();
        for(int i=0;i<topList.size();i++){
            SMTableZZJG top = topList.get(i);
            sb.append("{");
            sb.append("id:'"+top.getField000()+"'");
            sb.append(",pId:'"+top.getField003()+"'");
            sb.append(",name:'"+top.getField001()+"'");
            List<SMTableZZJG> subList = orgnService.getSubOrgn(top.getField000());
            sb.append(",iconSkin:'pIcon'");
            if(subList.size()>0)
            {//如果有子集,则保证打开,方便前端expand使用
                sb.append(",isParent:true");
            }
            else
            {
                sb.append(",isParent:false");
            }
            sb.append("},");
        }
        String str = sb.toString().substring(0, sb.toString().length()-1);
        return str;
    }

 

你可能感兴趣的:(ztree)