虽然说项目已经告一段落了,上个星期还是忙。搞定权限,优化代码,搭配外网运行环境。不满意权限树的超级无敌慢,自己摞起袖子上阵,还好有个DTree。自己还得抽空写文档。
最大的收获还是dtree,其实以前也曾经注意到DTree,不过那时候没有真正的用在实际的开发中,也没有太放到心上。感谢http://www.destroydrop.com。
这个dTree果然是非常的不错,正是我寻找的基于客户端的树。在MVC框架下这种基于客户端处理的树更是体现出了它的优势,而且在需要对树的效率进行优化时候也更有空间。
你只需要把需要显示的树的节点(s)传到客户端,其他的交给dTree来做。
根据dtree的javascript可以随意扩展,如下ex_dtree.js做简单的扩展:
---------------- ex_dtree.js -------------
function getRootId(root){
return root.aNodes[0].id;
}
function getRootName(root){
return root.aNodes[0].name;
}
function getSelectedId(root){
return root.aNodes[root.selectedNode].id;
}
function getSelectedNode(root){
alert(root.aNodes[root.selectedNode].name +"--"+ root.aNodes[root.selectedNode].id );
alert(root.selectedNode);
}
function getParentId(root){
return root.aNodes[root.selectedNode].pid;
}
function isSomeNodeSelected(root){
return (root.selectedNode == null || root.selectedNode == "undefined");
}
function forwardDelete(root){
if(isSomeNodeSelected(root)){
alert("请选中要删除的节点!");
return;
}
location.href = "tree.delete.do?rootid=" + getRootId(root) + "&rootname=" + getRootName(root) + "&id=" + getSelectedId(root);
}
function forwardAdd(root){
forwardUrl = "tree.treeadd.istjsp?rootid=" + getRootId(root) + "&rootname=" + getRootName(root) + "&parentId=" + getSelectedId(root);
parent.main.location.href = forwardUrl;
}
function forwardDetail(root){
if(isSomeNodeSelected(root)){
alert("请选中要修改的节点!");
return;
}
forwardUrl = "tree.detail.do?rootid=" + getRootId(root) + "&rootname=" + getRootName(root) + "&id=" + getSelectedId(root);
parent.main.location.href = forwardUrl;
}
一下树的显示页面
---------------- treedisplay.jsp -------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.istqz.com" prefix="istframe"%>
<%--
/**
* 树显示页面
* 功能:显示树、显示提示信息、右键功能
* @author: 黄新艺
* @version:
* @modify:
* @Copyright: 泉州创亿科技
*/
--%>
<HTML>
<HEAD>
<TITLE> Tree Displayer </TITLE>
<link rel="StyleSheet" href="commoncss/dtree.css" type="text/css"/>
<script type="text/javascript" src="commonjs/dtree.js"></script>
<script type="text/javascript" src="commonjs/ex_dtree.js"></script>
<SCRIPT language="javascript" src="commonjs/popmenu.js"></SCRIPT>
<script language="javascript">
function doRedirect(url){
parent.main.location.href=url;
}
</script>
</HEAD>
<BODY topmargin="0" onContextMenu="return false;" onMouseUp="showPopMenu();">
<%
String rootid = (String)request.getAttribute("rootid");
String rootname = (String)request.getAttribute("rootname");
java.util.List notes = (java.util.List)request.getAttribute("treefordisplay");
StringBuffer treeSb = new StringBuffer("<SCRIPT LANGUAGE=/"javascript/">/n");
treeSb.append(rootid);
treeSb.append("= new dTree('");
treeSb.append(rootid) ;
treeSb.append("','');/n");
treeSb.append(rootid);
treeSb.append(".config.useStatusText=true;/n");
treeSb.append(rootid) ;
treeSb.append(".config.useCookies=false;/n");
treeSb.append(rootid);
treeSb.append(".add('");
treeSb.append(rootid);//selfid
treeSb.append("','");
treeSb.append(-1);//parentid
treeSb.append("','");
treeSb.append(rootname);//selfname
treeSb.append("',");
treeSb.append("'javascript:void(0);');/n");
if(notes != null){
int size = notes.size();
for(int i = 0;i < size; i++){
Object[] vals = (Object[])notes.get(i);
treeSb.append(rootid);
treeSb.append(".add('");
treeSb.append(vals[0].toString());//selfid
treeSb.append("','");
if(vals[2] == null || vals[2].equals("")){
treeSb.append(rootid);//parentid
}else{
treeSb.append(vals[2].toString());//parentid
}
treeSb.append("','");
treeSb.append(vals[1].toString());//selfname
treeSb.append("',");
treeSb.append("'javascript:doRedirect(//'");
treeSb.append(vals[4].toString());
treeSb.append("//');');/n");
}
}
treeSb.append("document.write(");
treeSb.append(rootid);
treeSb.append(");/n");
treeSb.append("</SCRIPT>");
out.println(treeSb.toString());
%>
<istframe:popuMenu/>
<istframe:msgDialog/>
</BODY>
</HTML>
最大的收获还是dtree,其实以前也曾经注意到DTree,不过那时候没有真正的用在实际的开发中,也没有太放到心上。感谢http://www.destroydrop.com。
这个dTree果然是非常的不错,正是我寻找的基于客户端的树。在MVC框架下这种基于客户端处理的树更是体现出了它的优势,而且在需要对树的效率进行优化时候也更有空间。
你只需要把需要显示的树的节点(s)传到客户端,其他的交给dTree来做。
根据dtree的javascript可以随意扩展,如下ex_dtree.js做简单的扩展:
---------------- ex_dtree.js -------------
function getRootId(root){
return root.aNodes[0].id;
}
function getRootName(root){
return root.aNodes[0].name;
}
function getSelectedId(root){
return root.aNodes[root.selectedNode].id;
}
function getSelectedNode(root){
alert(root.aNodes[root.selectedNode].name +"--"+ root.aNodes[root.selectedNode].id );
alert(root.selectedNode);
}
function getParentId(root){
return root.aNodes[root.selectedNode].pid;
}
function isSomeNodeSelected(root){
return (root.selectedNode == null || root.selectedNode == "undefined");
}
function forwardDelete(root){
if(isSomeNodeSelected(root)){
alert("请选中要删除的节点!");
return;
}
location.href = "tree.delete.do?rootid=" + getRootId(root) + "&rootname=" + getRootName(root) + "&id=" + getSelectedId(root);
}
function forwardAdd(root){
forwardUrl = "tree.treeadd.istjsp?rootid=" + getRootId(root) + "&rootname=" + getRootName(root) + "&parentId=" + getSelectedId(root);
parent.main.location.href = forwardUrl;
}
function forwardDetail(root){
if(isSomeNodeSelected(root)){
alert("请选中要修改的节点!");
return;
}
forwardUrl = "tree.detail.do?rootid=" + getRootId(root) + "&rootname=" + getRootName(root) + "&id=" + getSelectedId(root);
parent.main.location.href = forwardUrl;
}
一下树的显示页面
---------------- treedisplay.jsp -------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.istqz.com" prefix="istframe"%>
<%--
/**
* 树显示页面
* 功能:显示树、显示提示信息、右键功能
* @author: 黄新艺
* @version:
* @modify:
* @Copyright: 泉州创亿科技
*/
--%>
<HTML>
<HEAD>
<TITLE> Tree Displayer </TITLE>
<link rel="StyleSheet" href="commoncss/dtree.css" type="text/css"/>
<script type="text/javascript" src="commonjs/dtree.js"></script>
<script type="text/javascript" src="commonjs/ex_dtree.js"></script>
<SCRIPT language="javascript" src="commonjs/popmenu.js"></SCRIPT>
<script language="javascript">
function doRedirect(url){
parent.main.location.href=url;
}
</script>
</HEAD>
<BODY topmargin="0" onContextMenu="return false;" onMouseUp="showPopMenu();">
<%
String rootid = (String)request.getAttribute("rootid");
String rootname = (String)request.getAttribute("rootname");
java.util.List notes = (java.util.List)request.getAttribute("treefordisplay");
StringBuffer treeSb = new StringBuffer("<SCRIPT LANGUAGE=/"javascript/">/n");
treeSb.append(rootid);
treeSb.append("= new dTree('");
treeSb.append(rootid) ;
treeSb.append("','');/n");
treeSb.append(rootid);
treeSb.append(".config.useStatusText=true;/n");
treeSb.append(rootid) ;
treeSb.append(".config.useCookies=false;/n");
treeSb.append(rootid);
treeSb.append(".add('");
treeSb.append(rootid);//selfid
treeSb.append("','");
treeSb.append(-1);//parentid
treeSb.append("','");
treeSb.append(rootname);//selfname
treeSb.append("',");
treeSb.append("'javascript:void(0);');/n");
if(notes != null){
int size = notes.size();
for(int i = 0;i < size; i++){
Object[] vals = (Object[])notes.get(i);
treeSb.append(rootid);
treeSb.append(".add('");
treeSb.append(vals[0].toString());//selfid
treeSb.append("','");
if(vals[2] == null || vals[2].equals("")){
treeSb.append(rootid);//parentid
}else{
treeSb.append(vals[2].toString());//parentid
}
treeSb.append("','");
treeSb.append(vals[1].toString());//selfname
treeSb.append("',");
treeSb.append("'javascript:doRedirect(//'");
treeSb.append(vals[4].toString());
treeSb.append("//');');/n");
}
}
treeSb.append("document.write(");
treeSb.append(rootid);
treeSb.append(");/n");
treeSb.append("</SCRIPT>");
out.println(treeSb.toString());
%>
<istframe:popuMenu/>
<istframe:msgDialog/>
</BODY>
</HTML>