通过ajax 后台传递的 区域id 选中ztree的节点 并展开节点

代码如下:

< script type = "text/javascript" >
    var flag = "<%=request.getParameter("
flag ")%>";
if (flag != "true") {
    flag = false;
} else {
    flag = true;
}
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(bal, regionIdList) {
        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
                    };
                    if (bal) {
                        if (reginTree.setbal(regionIdList, json.id)) {
                            json.checked = true;
                        }
                    }
                    treeNode.push(json);
                }
                console.dir(treeNode);
            } else {
                console.log("加载数据失败");
            }
            reginTree.loadZtree({
                callback: {
                    onCheck: reginTree.zTreeOnCheck
                }
            }, ‘tree‘, treeNode, function() {
                var treeObj = reginTree.getZtreeObj(‘tree‘);
                var nodes = treeObj.getCheckedNodes(true);
                $.each(nodes, function(i, value) {
                    treeObj.expandNode(value, true, false, true);
                });
            });
        });

$(‘#tree‘).css({
            ‘width‘: ‘400px‘,
            ‘height‘: ‘450px‘,
            ‘overflow‘: ‘auto‘
        });
        $(‘#tree‘).parent().css({
            ‘width‘: $(‘#tree‘).get(0).offsetWidth + ‘px‘,
            ‘height‘: $(‘#tree‘).get(0).offsetHeight + ‘px‘
        });

},
    //ztree节点选中   当选中节点时树形 结构展开
    zTreeOnCheck: function(event, treeId, treeNode) {
        var treeObj = reginTree.getZtreeObj(‘tree‘);

if (treeNode.checked == true) {
            //单选控制
            treeObj.checkAllNodes(false);
            treeObj.checkNode(treeNode, true, true, false);

var oner = treeObj.getCheckedNodes(true);
            treeObj.expandNode(treeNode, true, false, true);
        }
        /* var nodes = treeObj.getCheckedNodes(true);
        console.dir(nodes); */

/* var treeObj = reginTree.getZtreeObj(‘tree‘),
            nodes = treeObj.getCheckedNodes(true),
            v = "";
        for (var i = 0; i < nodes.length; i++) {
            v += nodes[i].name + ",";
            alert(nodes[i].id + "," + v); //获取选中节点的值
        } */
    },
    getCheckNode: function(id, bal, param) {
        var zTree = reginTree.getZtreeObj(id);
        var nodes = zTree.getCheckedNodes(bal);
        var arr = [];
        var i = 0;
        var len = nodes.length;
        console.dir(nodes);
        for (i = 0; i < len; i++) {
            arr.push(nodes[i][param]);
        }
        return arr.join();
    },
    setbal: function(regionIdList, id) {
        var arr = regionIdList.split(‘,‘);
        var i = 0;
        var len = arr.length;
        for (i = 0; i < len; i++) {
            if (arr[i] == id) {
                return true;
                break;
            }
        }
    }
};

$(function() {
    $(".submit").on("click", function() {
        var regionIds = reginTree.getCheckNode("tree", true, "id");
        if (flag == true) {
            var jsonr = {
                "regionIds": regionIds
            };
            _public_.getJson(jsonr, "frontServer?busiCode=SYSRegionGetAllName").done(function(data) {
                window.opener.setRegionIds(data.regionAllName, regionIds);
                window.close();
            });
        } else {
            window.opener.setRegionIds("", regionIds);
            window.close();
        }
    });
});
var regionJson = {};
var regionIdList = window.opener.getRegionIds();
var bal = false;
if (regionIdList != null || regionIdList != "") {
    /* regionJson = {"regionIdList":regionIdList}; */
    bal = true;
}

//console.dir(regionJson);

reginTree.loadArea(bal, regionIdList); < /script>

时间: 2024-10-07 16:39:41

通过ajax 后台传递的 区域id 选中ztree的节点 并展开节点的相关文章

Ajax案例4--&gt;接收后台传递的XML数据

jsp页面--fourthajax.jsp 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 <!DOCTYP

js ajax 向后台传递数组

//定义数组 var _arrays = []; for (var i = 0; i < 10; i++) { _shangpins.push(i); } //post $.post(href, {list: _arrays} ); //get post datas var shangpins = Request.Params.GetValues("list[]"); js ajax 向后台传递数组

ajax获取后台传递的json数据

最近在使用JQuery的ajax方法时,需要返回的数据为json数据,在success返回中数据处理会根据返回方式不同会采用不同的方式来生成json数据.在$.ajax方法中应该是如何来处理的,简单进行说明. 首先给出要传的json数据:[{"demoData":"This Is The JSON Data"}] 1,使用普通的aspx页面来处理 Js代码   $.ajax({ type: "post", url: "Default.a

Ajax后台只执行一次的解决方案

1 $.ajax({ 2 url: 'Ajax/OrderBy.aspx', 3 data: {AppIds: sortedAppids}, 4 dataType: 'xml', 5 type: 'POST', 6 success: function(xml) 7 { 8 alert("排序成功!"); 9 10 } 11 }); ajax在同步交互时,第一次提交正常,再第二次提交如果和上次提交的url地址相同时将不进行提交,会用上次的返回值.这样处理也许是ext别有良苦用心,但是,如

token的作用以及ajax中传递token的几种方法

目录 1.ajax中传递token的作用 2.ajax中传递token的几种方法 内容 1.ajax中传递token的作用 作用一:防止表单重复提交 主要原理是:用户提交表单后,会携带token到服务器,服务器将session中的token和用户请求带过来的token进行比较,如果相同,会将session中的token进行更新.若用户重复提交,则用户之后发过来的请求的token和服务器session中的token是不一致的,所以会导致之后的表单提交操作失败. 作用二:防止anti csrf 攻击

Ztree 指定ID节点的选中 和 指定ID节点的展开

直接代码 然后在给大家解释 var treeObj = $("#treeDemo"); $.fn.zTree.init(treeObj, setting, Znode1); zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo"); var node = zTree_Menu.getNodeByParam("id",pid ); zTree_Menu.selectNode(node,true);//指定选中I

前端JS对后台传递的timestamp的转换

后台传递的timestamp类型的数据的JSON: Date.prototype.format = function(format) { var o = { "M+" : this.getMonth() + 1,// month "d+" : this.getDate(),// day "h+" : this.getHours(),// hour "m+" : this.getMinutes(),// minute "

jsp页面向后台传递 不赋值 传递的默认值

<input type="hidden" name="leaderIdentity" value="${subject.leaderId }" /> 生成的代码是<input type="hidden" name="leaderIdentity" value /> 向后台传递的leaderIdentity 为0 像select checkbox radio这样的不赋值就为null f

在EasyUI实现点击有子节点的文字时展开但不选中,点击最终子节点才选中的功能

最近做的项目中,总是会遇到需要实现点击树目录的有子节点时展开目录,点击最终子节点才实现选中的功能的需求.下边我就直接黏贴一下代码出来吧,非常容易看懂,关键的就是在选中事件中加一个判断. $('#RepairTID').combotree({        url: '/RepairSub/GetRepTypeZ/?userRole=5',        required: true,        panelHeight: 'auto',        onLoadSuccess: functi