zoukankan      html  css  js  c++  java
  • 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);
        });

  • 相关阅读:
    使用Nginx实现反向代理
    nginx配置
    jsonp跨域实现单点登录,跨域传递用户信息以及保存cookie注意事项
    jsonp形式的ajax请求:
    面试题
    PHP设计模式_工厂模式
    Redis限制在规定时间范围内登陆错误次数限制
    HTTP 状态码简介(对照)
    Django 进阶(分页器&中间件)
    Django 之 权限系统(组件)
  • 原文地址:https://www.cnblogs.com/beyonce5888296/p/3519464.html
Copyright © 2011-2022 走看看