1. 程式人生 > >easyui樹動態加載參考

easyui樹動態加載參考

als null itl animate treenode 不存在 type tar 展開

這篇文章是拷貝的,多謝原作者

  友情連接: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); }

easyui樹動態加載參考