码迷,mamicode.com
首页 > Web开发 > 详细

js zTree的用法

时间:2015-09-06 16:20:27      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

代码如下:

<script type="text/javascript">
    var reginTree = {
    setting: {
        view: {
            fontCss: {
                color: "#000"
            }
        },
        check: {
            enable: true,
            chkboxType: {
                "Y": "p",
                "N": "p"
            }, //加上ps  当点击父节点时子节点全部选中
            children: "children"
        },
        data: {
            key: {
                checked: "checked"
            },
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: 0
            }
        }
    },
    //获取ztree对象
    getZtreeObj: function(id) {
        var zTree;
        if ($.fn.zTree.getZTreeObj(id) != null && $.fn.zTree.getZTreeObj(id) != undefined) {
            zTree = $.fn.zTree.getZTreeObj(id);
        }
        return zTree;
    },
    //初始化ztree
    loadZtree: function(json, id, treeNode, callback) {
        var setter = $.extend({}, reginTree.setting, json);
        $.fn.zTree.init($(‘#‘ + id), setter, treeNode);
        var zTree = reginTree.getZtreeObj(id);
        if (callback) callback();
    },
    //加载ztree
    loadArea: function() {
        var regionJson = {
            "level": "2"
        };
        var treeNode = [];
        _public_.getJson(regionJson, "frontServer?busiCode=02060203").done(function(data) {
            if (data.returnCode == "Y") {
                for (var i = 0; i < data.regionList.length; i++) {
                    var id = data.regionList[i].rid;
                    var pId = data.regionList[i].pid;
                    var name = data.regionList[i].regionName;
                    var json = {
                        "id": id,
                        "name": name,
                        "pId": pId
                    };
                    treeNode.push(json);
                }
            } else {
                console.log("加载数据失败");
            }
            reginTree.loadZtree({
                callback: {
                    onCheck: reginTree.zTreeOnCheck
                }
            }, ‘tree‘, treeNode);
        });
    },
    //ztree节点选中
    zTreeOnCheck: function(event, treeId, treeNode) {
        alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
    }
};
reginTree.loadArea();
</script>

技术分享

js zTree的用法

标签:

原文地址:http://www.cnblogs.com/nianzhilian/p/4785751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!