zTree 勾選checkbox

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


    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 + ')'));node

            },
            error: function (msg) {
                alert("失敗");
            }
        });
    }
    //獲取全部選中節點的值
    function GetCheckedAll() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes(true);
        var msg = "name--id--pid\n";
        for (var i = 0; i < nodes.length; i++) {
            msg += nodes[i].name+"--"+nodes[i].id+"--"+nodes[i].pId+"\n";
        }
        $("#msg").val();
        $("#msg").val(msg);
    }   
   
    //全選
    function CheckAllNodes() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        treeObj.checkAllNodes(true);
    }ajax

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

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

    }
    //禁用、解禁選中節點
    function Disabled1() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes();post

        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();url

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

    function Add() {blog

    }
    function AddChild() {utf-8

    }
    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);    });

相關文章
相關標籤/搜索