给已有的树形结构加个搜索框?请问怎么实现

贝尔727 2017-10-24 11:07:48
js的部分代码

var a_nodeIndex=new Array(); //所有结点的索引
var topNode; //最顶层的结点
var str1=""; //保存结点的显示状态
var str2=""; //保存结点的展开状态
var strName=new Array(); //保存所有结点的名字
var curNodeID="";
var ParentID=-1;
var isDisplayMenu=false; //确定菜单是否显示

function TreeNode(id,name,pid,type,ownid,urlStr)
{
this.id=id; //结点的ID
this.name=name; //结点的名字
this.url=urlStr; //结点的名字
this.pid=pid; //结点的父ID
this.type=type; //节点类型
this.ownID=ownid; //节点的在类型中的ID
this.isOpen=false; //结点是否展开
this.isLast=false; //是否是本层最后一个结点
this.isDisplay=""; //结点的显示状态,"none"不显示,""显示
this.isLeaf=false; //是否是叶子结点
this.items=new Array(); //结点的子结点数组
}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
jsp的代码
function createTree() {
var Node;
Node = new TreeNode(0,"所有部门",-1,"","0");
strName[strName.length] = "所有部门";
if (Node.pid == -1) { //判断是否为根结点
Node.isOpen=1;
Node.isDisplay="";
Node.isLast=1; //判断该结点是否为同一级结点的最后一个结点
topNode=Node;
}
a_nodeIndex[a_nodeIndex.length]=Node;
<%
String sUserID=ParamUtils.getSession(session,"userID");
int intPersonType = ParamUtils.getIntParameter(request, "type", 0);
String organizeId = ParamUtils.getSession(session, "deptid");
String companyId = ParamUtils.getStringParameter(request,"companyId","");
DeptUserTree selectUserTree = new DeptUserTree();
Vector V_Info = new Vector();

if(companyId.equals("")||(companyId=="")||(companyId==null)){
if (intPersonType == 9) { //控制组织体系的显示
V_Info=selectUserTree.getInitChildrenNodes(organizeId);
}else if(intPersonType == 3&&!sUserID.equals("1")){
List detpList = selectUserTree.getSubDeptID(sUserID);
for(int i=0;i<detpList.size();i++){
V_Info.addAll(selectUserTree.getInitChildrenNodedandu((String)detpList.get(i)));
}
} else {
V_Info=selectUserTree.getInitChildrenNodes();
}
} else {
V_Info=selectUserTree.getInitChildrenNodesC(sUserID,companyId);
}
NodeBean node = null;
for (int t = 0; t < V_Info.size(); t++) {
node = (NodeBean)V_Info.get(t);
String tempID = node.getId();
String tempPID = node.getPid();
String tempName = node.getOwnname();
String owntype = node.getOwntype();
String ownid = node.getOwnid();
%>
var Node=new TreeNode("<%=tempID%>","<%=tempName%>","<%=tempPID%>","<%=owntype%>","<%=ownid%>");
strName[strName.length]="<%=tempName%>";
if (Node.pid == -1) { //判断是否为根结点
Node.isOpen = 1;
Node.isDisplay = "";
Node.isLast = 1; //判断该结点是否为同一级结点的最后一个结点
topNode = Node;
}
a_nodeIndex[a_nodeIndex.length]=Node;
<%
}
%>
setPailie(); //去掉
setIsDisplay();
setIsOpen();
setItems();
setIsLast();
setIsLeaf();
}

/**
* 点击结点的名字则对应各自的连接
*/
function onClickTreeItem() {
var srcObj = window.event.srcElement;
if (srcObj.getAttribute("parentid") != -1) {
clearLastSel();
srcObj.style.background = '#000099';
srcObj.style.color = '#ffffff';
srcObj.style.cursor = 'hand';
var srcID=srcObj.getAttribute('orgid');
var srcName=srcObj.getAttribute('orgname');
if (srcName == "flow_user") {
curNodeID=srcID;
curNodeName=srcObj.getAttribute('name');
curType=srcName;
}
}
}

/**
* 点击结点的名字则对应各自的连接
*/
function ondbClickTreeItem() {
var srcObj=window.event.srcElement;
if (srcObj.getAttribute("parentid")!=-1) {
clearLastSel();
srcObj.style.background = '#000099';
srcObj.style.color = '#ffffff';
srcObj.style.cursor = 'hand';
var srcID=srcObj.getAttribute('orgid');
var srcName=srcObj.getAttribute('orgname');
//alert(srcID);
if(srcName == "flow_user"){
curNodeID=srcID;
curNodeName=srcObj.getAttribute('name')
parent.parent.objFrame.AddChip(curNodeID,curNodeName);
}else {
curNodeID=srcID;
var pid=srcObj.getAttribute('pid');
//alert('curNodeID='+curNodeID);
// alert('pid='+pid);
for(i=0;i< a_nodeIndex.length;i++){
//alert( '循环id=='+a_nodeIndex[i].pid);
if( (a_nodeIndex[i].pid=="D_"+curNodeID&&a_nodeIndex[i].type=="flow_user")||(a_nodeIndex[i].pid=="O_"+curNodeID&&a_nodeIndex[i].type=="flow_user"))
{
parent.parent.objFrame.AddChip(a_nodeIndex[i].ownID,a_nodeIndex[i].name);
}
}
}
}
}
function selectName(){
var name = document.getElementById("select").value;

}
</script>
</head>
<body onLoad="displayTree()" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<input type="text" id="select"> <input type="button" value="查询" onclick="selectName()">
<div id=TREE></div>
<form id="my_form" name="my_form" action="getChildrenNodes.jsp">
<input type=hidden name="type" value="<%=intPersonType%>">
<input type=hidden name="ID" >
<input type=hidden name="NodeType" >
</form>
<iframe id="my_iframe" name="my_iframe" width="0" height="0"></iframe>
</body>
</html>
...全文
623 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝尔727 2017-10-25
  • 打赏
  • 举报
回复
控件行吗?主要我的树结构js已经写好 加插件能行?
贝尔727 2017-10-25
  • 打赏
  • 举报
回复
我树结构 是js写的 我现在就差一步 如何自动的展开所有节点 帮忙 红包有偿!!谢谢 就差一步了
贝尔727 2017-10-24
  • 打赏
  • 举报
回复
查询那个input触发的事件selectName是我自己写的. 谁能帮我解决下!!谢谢大神们
奋斗_小伙 2017-10-24
  • 打赏
  • 举报
回复
jsTree 支持模糊查询功能 https://www.jstree.com/ 开源的 可以借鉴下

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧