/*** 1)扩展jquery easyui tree的节点检索方法。使用方法如下:* $("#treeId").tree("search", searchText);* 其中,treeId为easyui tree的根UL元素的ID,searchText为检索的文本。* 如果searchText为空或"",将恢复展示所有节点为正常状态*/
(function($) {$.extend($.fn.tree.methods, {/*** 扩展easyui tree的搜索方法* @param tree easyui tree的根DOM节点(UL节点)的jQuery对象* @param searchText 检索的文本* @param this-context easyui tree的tree对象*/search: function(jqTree, searchText) {debugger//easyui tree的tree对象。可以通过tree.methodName(jqTree)方式调用easyui tree的方法var tree = this;//获取所有的树节点var nodeList = getAllNodes(jqTree, tree);//如果没有搜索条件,则展示所有树节点searchText = $.trim(searchText);if (searchText == "") {for (var i=0; i0) {var node = null;for (var i=0; i0) {for (var i=0; i (containerH - 30)) {var scrollHeight = container.scrollTop() + nodeOffsetHeight - containerH + 30;container.scrollTop(scrollHeight);}}}});/*** 展示搜索匹配的节点*/function showMatchedNode(jqTree, tree, node) {//展示所有父节点$(node.target).show();$(".tree-title", node.target).addClass("tree-node-targeted");var pNode = node;while ((pNode = tree.getParent(jqTree, pNode.target))) {$(pNode.target).show();}//展开到该节点tree.expandTo(jqTree, node.target);//如果是非叶子节点,需折叠该节点的所有子节点if (!tree.isLeaf(jqTree, node.target)) {tree.collapse(jqTree, node.target);}}/*** 判断searchText是否与targetText匹配* @param searchText 检索的文本* @param targetText 目标文本* @return true-检索的文本与目标文本匹配;否则为false.*/function isMatch(searchText, targetText) {return $.trim(targetText)!="" && targetText.indexOf(searchText)!=-1;}/*** 获取easyui tree的所有node节点*/function getAllNodes(jqTree, tree) {var allNodeList = jqTree.data("allNodeList");if (!allNodeList) {var roots = tree.getRoots(jqTree);allNodeList = getChildNodeList(jqTree, tree, roots);jqTree.data("allNodeList", allNodeList);}return allNodeList;}/*** 定义获取easyui tree的子节点的递归算法*/function getChildNodeList(jqTree, tree, nodes) {var childNodeList = [];if (nodes && nodes.length>0) {var node = null;for (var i=0; i})(jQuery);