1:用sql查询出所有的树形数据,以orcale为例:
select c.CATEGORY_ID,c.PARENT_ID,ct.CATEGORY_NAME,c.IS_BOTTOM
from n_category c,n_categorytrans ct where ct.CATEGORY_ID=c.CATEGORY_ID
and ct.CUR_LANGUAGE='zh' and c.TYPE=3
start with c.PARENT_ID=0 connect by prior c.PARENT_ID=c.CATEGORY_ID
order by c.PARENT_ID,c.ORDER_NUMBER
出来的数据放到一个list里面。传到页面上。
List li = this.baseService.getListForSql(sql,new Object[]{curLanguage,type,0});
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("ncategoryTree", li);
2.jsp的页面如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
%>
<%@ include file="imports.jsp" %>
<script type="text/javascript" src="<%=path%>/js/jquery-1.1.4.js"></script>
<script type="text/javascript" src="<%=path%>/dtree/js/dtree.js"></script>
<table>
<tr>
<td colspan="2" bgcolor="#FFFFFF">
<input type="hidden" id="compassClassID" name="compass.compassclass.compassclassid"/>
<span id="nodeName"></span>
<span id="treeMessage"></span>
<script type="text/javascript">
var show = function (node) {
$("#compassClassID").val($(node).attr('cateid'));
$("#nodeName").html($(node).html());
$("#treeMessage").html("");
$("#compassClass").hide();
}
</script>
<input type="button" name="button" onclick="$('#compassClass').show();" value="选择"/>
<div id="compassClass" class="float">
<span onclick="$('#compassClass').hide();"><ww:text name="baseinfo-lable_GB"/></span>
<div id="theTree">
</div>
</div>
<script type="text/javascript">
var d = new dTree('d','<%=path%>');
d.add(0,-1,"<ww:text name='baseinfo-lable_QYLB'/>");
<c:forEach var="node" items="${ncategoryTree}">
var fnStr = "";
<c:if test="${node[3] == 1}">
fnStr = "show(this);";
</c:if>
d.add(${node[0]},${node[1]},'${node[2]}',fnStr);
</c:forEach>
$("#theTree").html(d.toString());
</script>
</td>
</tr>
<tr>
</table>