Ztree drop-down box multiple choice

~ Figure

 

 Code ~ po

  // document loads 
    $ (the Document) .ready ( function () {
         // load ztree tree 
        $ .fn.zTree.init ($ ( "# treeDemo" ), Setting, getJSON ());
        setCheck();
    });
// initial configuration 
    var Setting = {
        check: {
            enable: true
        },
        view: {
            dblClickExpand: false
        },
        data: {
            SimpleData: {
                enable: true
            }
        },
        callback: {
            beforeClick: beforeClick,
            onCheck: onCheck
        }

    };
    // Get personal data 
    function getJSON () {
         var STR = [];
        $.ajax({
            type: "Get",
            url: "/Schedule/GetUser",
            cache: false ,
            async: false,
            success: function (result) {
                str = result.data;
            }
        });
        return eval (str);
         // backstage return data, I was under ztree field to define because I am lazy ~ 
        // the above mentioned id: identifier 
        // pId: parent identifier 
        // the above mentioned id: identifier 
        // name: Name 
        // chkDisabled: checking whether 
        @ Open: whether to initiate 
    }
     // set the parent-child relationship 
    function SetCheck () {
         var zTree .fn.zTree.getZTreeObj $ = ( "treeDemo"), Py = "P", SY = "S ", PN =" P ", Sn =" S ", {type =" the Y ": Py + SY," N ": PN + Sn};
        zTree.setting.check.chkboxType = type;
    }
    //点击前
    function beforeClick(treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.checkNode(treeNode, !treeNode.checked, null, true);
        return false;
    }
    // trigger check 
    function onCheck (E, treeId, the treeNode) {
         var zTree .fn.zTree.getZTreeObj $ = ( "treeDemo" ),
            nodes = zTree.getCheckedNodes(true),
            namearray = new Array(),
            idarray = new new the Array ();
         // Get the child node data 
        for ( var I = 0, L = nodes.length; I <L; I ++ ) {
             // Get all the nodes 
            IF {(Nodes [I] .isParent!) / / acquisition sub-node 
                namearray.push (nodes [i] .name) ;
                idarray.push(nodes[i].id);
            }
            // the else { 
            //     // Get parent node 
            // } 
        }
        $("#userSel").val(namearray.join(','));
        $("#userValue").val(idarray.join(','));
    }
    // display the drop-down box UL 
    function showMenu is () {
         var cityObj = $ ( "# userSel" );
         var cityOffset = $ ( "# userSel" ) .offset ();
        $("#menuContent").css({ left: cityOffset.left + "px", top: cityOffset.top + cityObj.outerHeight() + "px" }).slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    }
    // hide the drop-down box ul 
    function HideMenu () {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    //下拉框ul发生变化
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "userSel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
            hideMenu ();
        }
    }
    // When editing, the check nodes have been selected 
    function refreshNode (ID) {
         var checkeduser = getJSON (ID) .toString () Split ( ','. );
         Var zTree .fn.zTree.getZTreeObj $ = ( "treeDemo" ),
            parnodes = new Array(),
            allnodes = zTree.transformToArray(zTree.getNodes()),
            namearray = new Array(),
            idarray = new Array(),
            flag = true;
        //获取子节点数据
        for (var i = 0, l = allnodes.length; i < l; i++) {
            if (!allnodes[i].isParent) {
                if (checkeduser.indexOf(allnodes[i].id) > -1) {
                    namearray.push(allnodes[i].name);
                    idarray.push(allnodes[i].id);
                    allnodes[i].checked = true;
                    zTree.updateNode(allnodes[i]);
                    // Get parent node of the current child node performs check 
                    parnodes = the allnodes [I] .getParentNode ();
                     IF (! Parnodes = null ) {
                        parnodes.checked = true;
                        zTree.updateNode(allnodes[i]);
                        while (flag) {
                            parnodes = parnodes.getParentNode();
                            if (parnodes != null) {
                                parnodes.checked = true;
                                zTree.updateNode (the allnodes [I]); // update the node 

                            } the else {
                                flag = false;
                            }
                        }
                    }
                }
            }

        }
        $("#userSel").val(namearray);
        $("#userValue").val(idarray);
    }     

Simple and crude po over the code, so be it ~ ~

Guess you like

Origin www.cnblogs.com/MuZiLily/p/12034674.html