• zTree 勾选checkbox


    var setting = {
        check: {
            enable: true
    //        chkboxType : { "Y" : "", "N" : "" }
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };


        function createTree () {
            var zNodes;
            $.ajax({
                url: 'Handler.ashx?action=GetModule', //url  action是方法的名称
                data: { id: "11" },
                type: 'POST',
                dataType: "text", //可以是text,如果用text,返回的结果为字符串;如果需要json格式的,可是设置为json
                ContentType: "application/json; charset=utf-8",
                success: function (data) {
                    zNodes = data;
                   
                    $.fn.zTree.init($("#treeDemo"), setting, eval('(' + zNodes + ')'));

                },
                error: function (msg) {
                    alert("失败");
                }
            });
        }
        //获取所有选中节点的值
        function GetCheckedAll() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes(true);
            var msg = "name--id--pid ";
            for (var i = 0; i < nodes.length; i++) {
                msg += nodes[i].name+"--"+nodes[i].id+"--"+nodes[i].pId+" ";
            }
            $("#msg").val();
            $("#msg").val(msg);
        }   
       
        //全选
        function CheckAllNodes() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            treeObj.checkAllNodes(true);
        }

        //全取消
        function CancelAllNodes() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            treeObj.checkAllNodes(false);
        }
       
        //选中指定的节点
        function AssignCheck() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    //        var nodes = treeObj.getNodes();

            treeObj.checkNode(treeObj.getNodeByParam("id", "000100010002", null), true, true);
            treeObj.checkNode(treeObj.getNodeByParam("id", "0001000100010001000100010001", null), true, true);

        }
        //禁用、解禁选中节点
        function Disabled1() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes();

            for (var i = 0; i < nodes.length; i++) {
                treeObj.setChkDisabled(nodes[i], true);
            }
        }
        function Disabled2() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes();

            for (var i = 0; i < nodes.length; i++) {
                treeObj.setChkDisabled(nodes[i], false);
            }
        }

        function Add() {

        }
        function AddChild() {

        }
        function Update() {

        }
        function Delete() {

        }
        function DeleteAll() {

        }

        $(document).ready(function () {
            createTree();
            $("#btn_GetCheckedAll").click(GetCheckedAll);
            $("#btn_CheckAllNodes").click(CheckAllNodes);
            $("#btn_CancelAllNodes").click(CancelAllNodes);
            $("#btn_AssignCheck").click(AssignCheck);
            $("#btn_Disabled1").click(Disabled1);
            $("#btn_Disabled2").click(Disabled2);

            $("#btn_Add").click(Add);
            $("#btn_AddChild").click(AddChild);
            $("#btn_Update").click(Update);
            $("#btn_Delete").click(Delete);
            $("#btn_DeleteAll").click(DeleteAll);
           
           
            //$.fn.zTree.init($("#treeDemo"), setting, zNodes);
        });

  • 相关阅读:
    【Python应用:基于PyQt5文本识别】调用百度AI对一张或多张图片、文件夹中的图片和屏幕区域截图进行识别(PDF转Word 小意思)
    【Ubuntu搭建Django编程环境】:创建python虚拟开发环境和配置pip国内镜像源
    23种设计模式上篇
    荷兰国旗问题
    文件复制多份
    mybatis批量更新
    数组小和
    常见排序算法
    福尔摩斯的约会
    小明上学
  • 原文地址:https://www.cnblogs.com/zhaoYuQing-java2015/p/6125480.html
Copyright © 2020-2023  润新知