当前位置 : 主页 > 编程语言 > c++ >

zTree插件的实现以及后台代码

来源:互联网 收集:自由互联 发布时间:2021-06-30
从数据库获取父级与子级的关系 package com.ninemax.treeNode.view.action;import java.io.IOException;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.apache.struts
从数据库获取父级与子级的关系
package com.ninemax.treeNode.view.action;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import com.paradise.bean.Condition;
import com.paradise.bean.Field;
import com.paradise.dao.FieldType;
import com.paradise.plus.BaseDaoPlus;

public class TreeNodeAction {
	/**
	 * 根据父类ID获取子类的树菜单
	 * @throws IOException
	 */
	public void findTreeByFid() throws IOException {
		
		Condition treeCondition=new Condition();
		treeCondition.add(new Field("F_ID",FieldType.STRING));
		treeCondition.add(new Field("F_GROUPID",FieldType.STRING));
		treeCondition.add(new Field("F_WORD",FieldType.STRING));
		String json="[";
		String sql="SELECT DISTINCT r1.* FROM (SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <= 15000 ) r1,"
				+ "(SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <=15000 ) r2"
				+ " WHERE r1.F_ID = r2.F_GROUPID UNION SELECT DISTINCT r4.* FROM (SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <=15000) r3,"
				+ "(SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <= 15000) r4 WHERE r3.F_ID = r4.F_GROUPID";
		System.out.println(sql);
		String jsonArr=BaseDaoPlus.find(sql, treeCondition);
		JSONArray arr=JSONArray.fromObject(jsonArr);
		for(int i=0;i
 

  
   struts配置文件(需要在主文件中导入struts配置文件)
  

  
   


   
	
     
      
       
      
    

   
前端实现代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
   <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
   <%
     String path = request.getContextPath();
     String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
   %>
      
      
         
            
    
            tree view
			
     
            
			
			
			
            
          
          
	    
   
		   
     
      
       
       
  • 资源分类
$(function(){ $.ajax({ type : "post", async:false, url : basePath + "admin/treeNode/treeNodeAction_findTreeByFid.action?d=" + Math.random(), dataType : "text", success:drawTree, error : function(data){alert(data);} }); }); function drawTree(data){ var setting = { view: { dblClickExpand: false }, data: { key: { //title:"name" }, simpleData: { enable: true } }, check: { enable: true }, callback: { //onClick: onClick } }; var zNodes =eval(data); alert(zNodes); $.fn.zTree.init($("#sourceTree"), setting, zNodes); var treeObj=$.fn.zTree.getZTreeObj("sourceTree"); treeObj.expandAll(false); }
网友评论