欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Easyui的combobox實現(xiàn)動態(tài)數(shù)據(jù)級聯(lián)效果

 更新時間:2016年06月12日 15:14:42   作者:海潛  
這篇文章主要介紹了Easyui的combobox實現(xiàn)動態(tài)數(shù)據(jù)級聯(lián)效果的相關(guān)資料,感興趣的小伙伴們可以參考一下

實現(xiàn)從數(shù)據(jù)庫中動態(tài)獲取對應(yīng)的List集合,并在Easyui的combobox中顯示出來。

實現(xiàn)的效果如下:






1、數(shù)據(jù)庫的表設(shè)計如圖所示



2、數(shù)據(jù)庫中填寫相關(guān)的數(shù)據(jù),如圖所示。如圖所示【法律法規(guī)】是所屬欄目,因此他的字段parentid是0?!局袊癯鰢?、【內(nèi)地居民往來港澳】是屬于法律法規(guī)的類別。因此他們的字段parentid是對應(yīng)1,【法律法規(guī)】的字段categoryid是1.


3、相關(guān)的配置:已經(jīng)在前面的博客中寫了http://www.dbjr.com.cn/article/86381.htm

 這里就不多寫。只把關(guān)鍵代碼貼出來。

4、對應(yīng)的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;
 }
 
 //根據(jù)欄目的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());// 轉(zhuǎn)化為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、對應(yīng)的接口代碼

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

6、對應(yīng)的接口實現(xiàn)類代碼

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、對應(yīng)的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默認(rèn)的CSS格式--藍(lán)色 -->
<link rel="stylesheet" type="text/css" href="<%=path%>/easyui_1.3.2/themes/default/easyui.css" />
<!-- 引入easyUi小圖標(biāo) -->
<link rel="stylesheet" type="text/css" href="<%=path%>/easyui_1.3.2/themes/icon.css" />

<script type="text/javascript">
 /* 初始化下載表格信息 */
 $(function() { 
 // 下拉框選擇控件,下拉框的內(nèi)容是動態(tài)查詢數(shù)據(jù)庫信息
 $('#lanmu').combobox({ 
  url:'itemManage!categorytbl', 
  editable:false, //不可編輯狀態(tài)
  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, //不可編輯狀態(tài)
  cache: false,
  panelHeight: 'auto',//自動高度適合
  valueField:'categoryid', 
  textField:'categoryName'
 });
 
 });
</script>


</head>
<body>

 
 <!-- 工具攔 -->
 <div id="tb" style="padding: 3px">
 <form >

 <span>所屬欄目:</span> 
 <select id="lanmu" class="lanmu" style="width:160px; border: 1px solid #ccc"> </select>
 <span>類別:</span> 
 <select id="leibie" class="leibie" style="width:160px; border: 1px solid #ccc"> </select>
 
 </form>
 </div>
 
</body>
</html>


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java集合定義與用法實例總結(jié)【Set、List與Map】

    Java集合定義與用法實例總結(jié)【Set、List與Map】

    這篇文章主要介紹了Java集合定義與用法,結(jié)合實例形式總結(jié)分析了Java集合中Set、List和Map相關(guān)概念、功能、用法及操作注意事項,需要的朋友可以參考下
    2018-08-08
  • 帶你入門Java的類與對象

    帶你入門Java的類與對象

    下面小編就為大家?guī)硪黄钊肜斫釰ava 對象和類。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能給你帶來幫助
    2021-07-07
  • Spring 中優(yōu)雅的獲取泛型信息的方法

    Spring 中優(yōu)雅的獲取泛型信息的方法

    這篇文章主要介紹了Spring 中優(yōu)雅的獲取泛型信息的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Java中數(shù)組的定義和使用教程(三)

    Java中數(shù)組的定義和使用教程(三)

    這篇文章主要給大家介紹了關(guān)于Java中數(shù)組的定義和使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Java基礎(chǔ)之extends用法詳解及簡單實例

    Java基礎(chǔ)之extends用法詳解及簡單實例

    這篇文章主要介紹了 Java基礎(chǔ)之extends用法詳解及簡單實例的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Docker容器中的SSH免密登錄詳解

    Docker容器中的SSH免密登錄詳解

    這篇文章主要介紹了Docker容器中的SSH免密登錄詳解,在日常的開發(fā)和測試環(huán)境中經(jīng)常需要創(chuàng)建和管理Docker容器,有時,出于調(diào)試或管理的目的,可能需要SSH到容器內(nèi)部,本文將介紹如何創(chuàng)建一個Docker容器,它在啟動時自動運行SSH服務(wù),并支持免密登錄,需要的朋友可以參考下
    2023-08-08
  • java文件下載代碼實例(單文件下載和多文件打包下載)

    java文件下載代碼實例(單文件下載和多文件打包下載)

    這篇文章主要介紹了java文件下載代碼實例(單文件下載和多文件打包下載),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-12-12
  • 淺析java程序入口main()方法

    淺析java程序入口main()方法

    這篇文章主要介紹了淺析java程序入口main()方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • DUCC配置平臺實現(xiàn)一個動態(tài)化線程池示例代碼

    DUCC配置平臺實現(xiàn)一個動態(tài)化線程池示例代碼

    這篇文章主要為大家介紹了DUCC配置平臺實現(xiàn)一個動態(tài)化線程池示例代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • RocketMQ發(fā)送事務(wù)消息詳解

    RocketMQ發(fā)送事務(wù)消息詳解

    這篇文章主要介紹了RocketMQ發(fā)送事務(wù)消息詳解,RocketMQ分布式事務(wù)消息不僅可以實現(xiàn)應(yīng)用之間的解耦,又能保證數(shù)據(jù)的最終一致性,傳統(tǒng)的大事務(wù)可以被拆分為小事務(wù),不僅能提升效率,還不會因為某一個關(guān)聯(lián)應(yīng)用的不可用導(dǎo)致整體回滾,需要的朋友可以參考下
    2023-09-09

最新評論