0

现在在 ztree 中,如果检查了任何子节点,那么它也会检查它的父节点,但我不想检查它的父节点。有什么办法吗?

var setting = {
        view: {
            dblClickExpand: true,
            selectedMulti: false,
            showLine: false,
            nameIsHTML: true,

        },
        check: {
            enable: true,                
        },
        data: {
            simpleData: {
                enable: true
            }
        },           
    };
4

1 回答 1

1

根据文档

setting.check.chkboxType:

当一个节点被选中或取消选中时,控制其父节点及其子节点自动选中或取消选中。当 [setting.check.enable = true & setting.check.chkStyle = "checkbox"] 时有效

默认值:{“Y”:“ps”,“N”:“ps”}

因此,我建议使用:

check: {
     enable: true,
    chkboxType: { "Y": "s", "N": "s" }
},

var setting = {
    view: {
        dblClickExpand: true,
        selectedMulti: false,
        showLine: false,
        nameIsHTML: true,

    },
    check: {
        enable: true,
        chkboxType: { "Y": "s", "N": "s" }
    },
    data: {
        simpleData: {
            enable: true
        }
    }
};
var zTreeObj;
var zNodes = [
    {name:"test1", open:true, children:[
        {name:"test1_1"}, {name:"test1_2"}]},
    {name:"test2", open:true, children:[
        {name:"test2_1"}, {name:"test2_2"}]}
];

zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zTree/zTree_v3@master/css/demo.css" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zTree/zTree_v3@master/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/zTree/zTree_v3@master/js/jquery.ztree.all.js"></script>


<div>
    <ul id="treeDemo" class="ztree"></ul>
</div>

于 2019-05-22T20:07:07.460 回答