程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> Easyui的combobox完成靜態數據級聯後果

Easyui的combobox完成靜態數據級聯後果

編輯:關於JAVA

Easyui的combobox完成靜態數據級聯後果。本站提示廣大學習愛好者:(Easyui的combobox完成靜態數據級聯後果)文章只能為提供參考,不一定能成為您想要的結果。以下是Easyui的combobox完成靜態數據級聯後果正文


完成從數據庫中靜態獲得對應的List聚集,並在Easyui的combobox中顯示出來。

完成的後果以下:






1、數據庫的表設計如圖所示



2、數據庫中填寫相干的數據,如圖所示。如圖所示【司法律例】是所屬欄目,是以他的字段parentid是0。【中國國民出國】、【邊疆居平易近來往港澳】是屬於司法律例的種別。是以他們的字段parentid是對應1,【司法律例】的字段categoryid是1.


3、相干的設置裝備擺設:曾經在後面的博客中寫了http://www.jb51.net/article/86381.htm

 這裡就不多寫。只把症結代碼貼出來。

4、對應的Action代碼

package crj.portal.web.management.action;


import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.sun.tools.javac.util.Log;

import crj.portal.web.management.model.Cpersontypetbl;
import crj.portal.web.management.service.CategoryService;
import crj.portal.web.management.service.ItemService;
import crj.portal.web.management.service.UserService;


public class ItemManageAction {


 Logger log=Logger.getLogger(this.getClass());
 
 private String page;
 private String rows;
 
 private String lanmuid;
 
 private ItemService itemService;// 依附注入
 
 
 //下拉框--查詢欄目
 public String categorytbl() throws Exception{
 List list=itemService.queryLanMu();
 this.toJsonArray(list);
 return null;
 }
 
 //依據欄目標ID 查詢具有的種別
 public String leibie() throws Exception{
 List list=itemService.queryLeiBie(lanmuid);
 this.toJsonArray(list);
 return null;
 }
 
 public String toJsonArray(List list) throws IOException{
 HttpServletResponse response = ServletActionContext.getResponse();
 HttpServletRequest request = ServletActionContext.getRequest();
 
 JSONArray json = JSONArray.fromObject(list);
 log.info("JSON格局:" +json.toString()); 
  response.setCharacterEncoding("utf-8");// 指定為utf-8
  response.getWriter().write(json.toString());// 轉化為JSOn格局
 return null;
 }
 
 public String save() throws Exception {
 return this.alllist();
 }


 public ItemService getItemService() {
 return itemService;
 }

 public void setItemService(ItemService itemService) {
 this.itemService = itemService;
 }

 public String getPage() {
 return page;
 }

 public void setPage(String page) {
 this.page = page;
 }

 public String getRows() {
 return rows;
 }

 public void setRows(String rows) {
 this.rows = rows;
 }

 public UserService getUserService() {
 return userService;
 }

 public void setUserService(UserService userService) {
 this.userService = userService;
 }

 public CategoryService getCategoryService() {
 return categoryService;
 }

 public void setCategoryService(CategoryService categoryService) {
 this.categoryService = categoryService;
 }

 public String getLanmuid() {
 return lanmuid;
 }

 public void setLanmuid(String lanmuid) {
 this.lanmuid = lanmuid;
 }
 
 

}

 5、對應的接口代碼

public interface ItemService {
 
 //下拉框--查詢欄目
 public List queryLanMu() throws Exception;
 
 //下拉框--查詢種別
 public List queryLeiBie(String ids) throws Exception; 
 
} 

6、對應的接話柄現類代碼

public class ItemServiceImpl implements ItemService {
 Logger log = Logger.getLogger(this.getClass());
 private SessionFactory sessionFactory;

 //下拉框--查詢欄目
 public List queryLanMu() throws Exception {
 Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(Categorytbl.class);
 criteria.add(Restrictions.eq("parentid", 0));
 criteria.addOrder(Order.asc("categoryid"));
 return criteria.list();
 }

 //下拉框--查詢種別
 public List queryLeiBie(String ids) throws Exception {
 int i=Integer.parseInt(ids);
 Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(Categorytbl.class);
 criteria.add(Restrictions.eq("parentid", i));
 criteria.addOrder(Order.asc("categoryid"));
 return criteria.list();
 }
 public SessionFactory getSessionFactory() {
 return sessionFactory;
 }

 public void setSessionFactory(SessionFactory sessionFactory) {
 this.sessionFactory = sessionFactory;
 }

} 


7、對應的JSP代碼

<%@ page language="java" errorPage="/error.jsp" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<%
 String path = request.getContextPath();
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>信息治理</title>
<!-- 引入Jquery -->
<script type="text/javascript" src="<%=path%>/easyui_1.3.2/jquery-1.8.0.min.js" charset="utf-8"></script>
<!-- 引入Jquery_easyui -->
<script type="text/javascript" src="<%=path%>/easyui_1.3.2/jquery.easyui.min.js" charset="utf-8"></script>
<!-- 引入easyUi國際化--中文 -->
<script type="text/javascript" src="<%=path%>/easyui_1.3.2/locale/easyui-lang-zh_CN.js" charset="utf-8"></script>
<!-- 引入easyUi默許的CSS格局--藍色 -->
<link rel="stylesheet" type="text/css" href="<%=path%>/easyui_1.3.2/themes/default/easyui.css" />
<!-- 引入easyUi小圖標 -->
<link rel="stylesheet" type="text/css" href="<%=path%>/easyui_1.3.2/themes/icon.css" />

<script type="text/javascript">
 /* 初始化下載表格信息 */
 $(function() { 
 // 下拉框選擇控件,下拉框的內容是靜態查詢數據庫信息
 $('#lanmu').combobox({ 
  url:'itemManage!categorytbl', 
  editable:false, //弗成編纂狀況
  cache: false,
  panelHeight: 'auto',//主動高度合適
  valueField:'categoryid', 
  textField:'categoryName',
  
 onHidePanel: function(){
  $("#leibie").combobox("setValue",'');
 var lanmuid = $('#lanmu').combobox('getValue'); 
 
 $.ajax({
 type: "POST",
 url: "itemManage!leibie?lanmuid="+lanmuid,
 cache: false,
 dataType : "json",
 success: function(data){
 $("#leibie").combobox("loadData",data);
   }
  }); 
  }
   }); 
 
 $('#leibie').combobox({ 
  //url:'itemManage!categorytbl', 
  editable:false, //弗成編纂狀況
  cache: false,
  panelHeight: 'auto',//主動高度合適
  valueField:'categoryid', 
  textField:'categoryName'
 });
 
 });
</script>


</head>
<body>

 
 <!-- 對象攔 -->
 <div id="tb" >
 <form >

 <span>所屬欄目:</span> 
 <select id="lanmu" class="lanmu" > </select>
 <span>種別:</span> 
 <select id="leibie" class="leibie" > </select>
 
 </form>
 </div>
 
</body>
</html>


以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved