java树形菜单编辑保存

JavaScript027

java树形菜单编辑保存,第1张

在图形界面中添加文本框架实现文本编辑,通过鼠标菜单栏添加事件监听实现保存。

在开发中我们经常会遇到左边是树形菜单,右边是一个显示列表,单击左边的树形菜单项时,右边会显示该菜单里面相对应的内容。在实战开发中经常有需要处理树形菜单、树形目录等等等业务需求。

而对于这种产品,在设计数据库时也建议使用idparentId的结构来做。

其实很简单,就是在你

if (document.getElementById('node' + no).style.display == 'none') {

document.getElementById('node' + no).style.display = 'block'}// 如果此层是隐藏的

这段里面在加一句所有子层隐藏就可以了

if (document.getElementById('node' + no).style.display == 'none') {

(要加在这里哦~要是加在document.getElementById('node' + no).style.display = 'block'这句下面就永远不会有子项显示)

document.getElementById('node' + no).style.display = 'block'}

jsp动态树形菜单须用到递归算法,比如在数据库有张表,parent表,parent的字段有id,name,depth,leve,ID自增,depth设置为级数,如这条数据最大,为0,如为字菜单就为1,而leve就指定它父节点的id,给段代码自己可以摸索下 public Vector getModuleTree()

{

Vector pclass = new Vector()

try

{

stmt =con.createStatement()

String sql = "select * from Module where parentid = 0"

rs = stmt.executeQuery(sql)

Module cvo = null

while(rs.next())

{

cvo = new Module()

cvo.setModule_id(rs.getInt("Module_id"))

cvo.setModule_name(rs.getString("Module_name"))

cvo.setModule_url(rs.getString("Module_url"))

cvo.setParentid(rs.getInt("parentid"))cvo.setRootid(rs.getInt("rootid"))cvo.setDepth(rs.getInt("depth"))pclass.add(cvo)

}

for (int i = 0i <pclass.size()i++)

{

Module pcvo = (Module) pclass.get(i)

ShowTreeMenu(pcvo)

}

con.commit() } catch (SQLException e)

{

e.printStackTrace()

} finally

{

try

{

if(rs!=null)

{

rs.close()

}

if(stmt!=null)

{

stmt.close()

}

if(con!=null)

{

con.close()

}

}

catch (SQLException e)

{

e.printStackTrace()

}

}

return classList

}

public void ShowTreeMenu(Module c)

{

Module ccvo = null

String sql = "select * from Module where parentid = " + c.getModule_id()

Vector cclass = new Vector()

try

{

Module cvotemp

stmt =con.createStatement()

rs = stmt.executeQuery(sql)

while(rs.next())

{

cvotemp = new Module()

cvotemp.setModule_id(rs.getInt("Module_id"))

cvotemp.setModule_name(rs.getString("Module_name"))

cvotemp.setModule_url(rs.getString("Module_url"))

cvotemp.setParentid(rs.getInt("parentid"))cvotemp.setRootid(rs.getInt("rootid"))cvotemp.setDepth(rs.getInt("depth"))cclass.add(cvotemp)

}

System.out.println(cclass.size()+"(((((((((((((((((((((((((9")

if (cclass.size() >0)

{

c.setHasChild("have")

classList.add(c)

for (int j = 0j <cclass.size()j++)

{

ccvo = (Module) cclass.get(j)

ShowTreeMenu(ccvo)

}} else

{

classList.add(c)

}

} catch (SQLException e)

{

e.printStackTrace()

}

}