在art.dialog中加载ztree

var zNodes;
$("#btnsetlx").click(function () {
    var arr = [8,9,10];//默认选中值,可以动态取值
    layer.load(5);
    $.ajax({
        url: "/sysadmin/lanmu/GetList",
        data: {},
        dataType: "json",
        type: "get",
        complete: function (xtr, status) {
            layer.closeAll("loading");
        },
        error: function (xtr, status, errmsg) {
            art.dialog({
                title: "错误",
                lock: true,
                content: errmsg,
                icon:"error"
            });
        },
        success: function (json) {
            if (json.Err == 0) {
                art.dialog({
                    title:"选择目录",
                    lock:true,
                    content: "<div><ul class=\"ztree\" id=\"ztree\"></ul></div>",
                    cancel: true,
                    ok:function(){
                        var ztree = $.fn.zTree.getZTreeObj("ztree");
                        var nodes = ztree.getCheckedNodes(true);
                        var sarr = [];
                        for (var i = 0; i < nodes.length; i++) {
                            sarr.push("<span data-id=\"" + nodes[i].LmId + "\">" + nodes[i].LmName + "</span>");
                        }
                        $("#mycate").html(sarr.join("、"));
                    },
                    init: function () {
                        /*初始化ztree begin*/
                        this.zNodes = json.Data;
                        var setting = {
                            view: {
                                showIcon: false,
                                selectedMulti: true//多选
                            },
                            check: {
                                enable: true,
                                nocheckInherit: true,
                                chkStyle: "checkbox",
                                chkboxType:{"Y":"","N":""}
                            },
                            key: {
                                name: "LmName",
                                id: "LmId"
                            },
                            data: {
                                simpleData: {
                                    enable: true,
                                    idKey: "LmId",
                                    pIdKey: "ParentId"
                                },
                                key: {
                                    name: "LmName"
                                }
                            },
                            callback: {
                                onMouseDown: function (event, treeId, treeNode) {},
                                onClick: function(event, treeId, treeNode){}
                            }
                        };
                        $.fn.zTree.init($("#ztree"), setting, this.zNodes);
                        /*初始化ztree end*/
                        //加载后,根据默认选中值设置文字
                        if (arr.length > 0) {
                            var ztree = $.fn.zTree.getZTreeObj("ztree");
                            for (var i = 0; i < arr.length; i++) {
                                for (var j = 0; j < this.zNodes.length; j++) {
                                    if (this.zNodes[j].LmId == arr[i]) {
                                        //设置勾选
                                        ztree.checkNode(ztree.getNodeByParam("LmId", arr[i]), true);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }
    });
});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值