我是徐大志

有志者事竟成,破釜沉舟,百二秦关终属楚;
苦心人天不负,卧薪尝胆,两千越甲可吞吴。

easyui树动态加载参考

这篇文章是拷贝的,多谢原作者

  友情连接:http://www.jb51.net/article/28771.htm

var treeTitle = '选择列表';
var treeUrl = '../DataAshx/getTreeNode.ashx?pid=-1';
var nodeExp = false;
var nodekeep = "";
var rows;
var noinf = 0;
$(function () {
    $('#treewindow').window({
        title: treeTitle,
        width: 400,
        height: 400,
        modal: true,
        shadow: false,
        closed: true,
        resizable: false,
        maximizable: false,
        minimizable: false,
        collapsible: false
    });
});

function treeWindowOpen(name, rowIndx) {
    $('#treewindow').window('open');
    nodekeep = "";
    nodeExp = false;
    rows = rowIndx.toString();
    $('#basetree').tree({
        checkbox: true,
        animate: true,
        url: treeUrl + "&coln=" + escape(name.toString()),
        cascadeCheck: true,
        onlyLeafCheck: false,
        onBeforeExpand: function (node, param) {
            //------------第一种方法:异步加载子节点值-------------
            // $('#basetree').tree('options').url = "../DataAshx/getTreeNode.ashx?pid=" + node.id+"&coln="+escape(name.toString());

            //------------第二种方法:Ajax方法返回子节点Json值,使用append方法加载子节点
            $.ajax({
                type: "POST",
                url: "../DataAshx/getTreeNode.ashx?pid=" + node.id + "&coln=" + escape(name.toString()) + "&casn=" + escape(node.attributes.cas.toString()),
                cache: false,
                async: false,
                dataType: "json",
                success: function (data) {
                    if (nodekeep.indexOf(node.id) == -1) {
                        append(data, node);
                        nodeExp = true;
                    }
                }
            });
            $("#radCollapse").removeAttr("checked");
        },
        onLoadError: function (Error) {
            $.messager.alert('提示', '查询语句出错', 'error');
            if (nodeExp == false) {
                $("#basetree").children().remove();
            }
        },
        onLoadSuccess: function (success) {
            var child = $("#basetree").children().length;
            noinf++;
            if (child == 0 && noinf > 1) {
                $.messager.alert('提示', '数据不存在', 'Info');
            }
        }
    });

}

function treeWindowClose() {
    $('#treewindow').window('close');
    nodekeep = "";
    nodekeep = false;
}

function treeWindowSubmit() {
    var nodes = $('#basetree').tree('getChecked');
    var info = '';
    if (nodes.length > 0) {
        for (var i = 0; i < nodes.length; i++) {
            if (info != '') {
                info += ',';
            }
            info += nodes[i].text;
        }
//alert(JSON.stringify(nodes));
    }
    else {
        var node = $('#basetree').tree('getSelected');
        if (node != null) {
            info = node.text;
        }
    }
    $("#" + rows).val(info);
    $('#treewindow').window('close');
    nodekeep = "";
    nodeExp = false;
}

//全部展开
function collapseAll() {
    $("#radCollapse").attr("checked", "checked");
    var node = $('#basetree').tree('getSelected');
    if (node) {
        $('#basetree').tree('collapseAll', node.target);
    } else {
        $('#basetree').tree('collapseAll');
    }
}

//全部收缩
function expandAll() {
    var node = $('#basetree').tree('getSelected');
    if (node) {
        $('#basetree').tree('expandAll', node.target);
    } else {
        $('#basetree').tree('expandAll');
    }
}

//增加子节点
function append(datas, cnode) {
    var node = cnode;
    $('#basetree').tree('append', {
        parent: node.target,
        data: datas
    });
    nodekeep += "," + node.id;
}

//重新加载
function reload() {
    var node = $('#basetree').tree('getSelected');
    if (node) {
        $('#basetree').tree('reload', node.target);
    } else {
        $('#basetree').tree('reload');
    }
}

//删除子节点
function remove() {
    var node = $('#basetree').tree('getSelected');
    $('#basetree').tree('remove', node.target);
}

 

posted @ 2017-12-13 09:41  我是徐大志  阅读(1978)  评论(1编辑  收藏  举报
【少年,我看你目光炯炯有神,将来一定能成大事!】