ztree不显示父级的复选框 查看当前被选中的节点的级数

 //去掉一级复选框
    getChecked = () => {
        //获取到zTree
        let allNodes = this.zTreeCatalog.getNodes()
        if (allNodes.length > 0) {
            for (let i = 0; i < allNodes.length; i++) {
                if (allNodes[i].isParent) {
                    allNodes[i].nocheck = true;//nocheck为true表示没有选择框
                }
            }
        }
    }




this.zTreeCatalog = global.zTreeCatalog = $.fn.zTree.init($("#layerCatalog"), setting, list);

nocheck:true;不显示复选框,

isParent:第一级显示目录

第一种:通过传递的参数:treeNode可以获取到层级

treeNode.level

第二种:

var treeObj = $.fn.zTree.getZTreeObj("tree");
var sNodes = treeObj.getSelectedNodes();
if (sNodes.length > 0) {
	var level = sNodes[0].level;
}

<!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - checkbox</TITLE> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="zTreeStyle.css" type="text/css"> <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript" src="jquery.ztree.core.js"></script> <script type="text/javascript" src="jquery.ztree.excheck.js"></script> <SCRIPT type="text/javascript"> var setting = {check: {enable: true},data: {simpleData: {enable: true}}}; var zNodes =[ { id:1, pId:0, name:"全选", open:true}, { id:11, pId:1, name:"报表", open:true}, { id:111, pId:11, name:"报表管理",open:true}, { id:112, pId:11, name:"报表概况",open:true}, { id:12, pId:1, name:"我的", open:true}, { id:121, pId:12, name:"修改密码",open:true}, { id:122, pId:12, name:"意见反馈",open:true} ]; $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); var zTree = $.fn.zTree.getZTreeObj("treeDemo"), type = { "Y":'ps', "N":'ps'}; zTree.setting.check.chkboxType = type; }); function aa(){ var treeObj=$.fn.zTree.getZTreeObj("treeDemo"); nodes=treeObj.getCheckedNodes(true); var nodes1 = treeObj.getNodes(); var aa1= treeObj.transformToArray(nodes1); for(var i=0; i < aa1.length;i++){ var node = treeObj.getNodeByParam("id",aa1[i].id ); treeObj.checkNode(node,true,true); treeObj.updateNode(node); } } </SCRIPT> </HEAD> <BODY> <div class="content_wrap"> <div class="zTreeDemoBackground left"> <ul id="treeDemo" class="ztree"></ul> </div> <button value="dianji" onclick="aa()" /> </div> </BODY> </HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值