Jquery UI 组合树 - ComboTree 集成Wabacus4.1 代码剖析
Jquery UI 1.3 (组合树 - ComboTree ) 集成Wabacus4.1 集成Spring 代码剖析
使用时,请下载需要Jquery ui包进行配置
combotree.js 的代码,可以不用修改, 只是Wabacus中的编辑少量配置一下即可,此例子只进行了2级的菜单拼接,如需修改,只需将方法修改成递归拼接即可
如:
首先combotree.js代码
var dataurl,valuefield,textfield; /**
* 加载树形下拉框
*/
function loadComboTree(){
dataurl = $('input.easyui-combotree').attr("dataurl");
valuefield = $('input.easyui-combotree').attr("valuefield");
textfield = $('input.easyui-combotree').attr("textfield");
//alert(dataurl);
$('input.easyui-combotree').combotree({
url:dataurl, //data : json,
valueField : valuefield,
textField : textfield,
editable: false, //定义用户是否可以直接输入文本到选择框默认false
animate:true, //展开/折叠节点的时候是否显示效果
onClick : function(node) {
//alert(node.id+"___"+node.text);
$('input.easyui-combotree').val(node.id); // 赋值
},
onSelect : function(node) {
//返回树对象
var tree = $(this).tree;
//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
var isLeaf = tree('isLeaf', node.target);
if (!isLeaf) {
//清除选中
$('input.easyui-combotree').combotree('clear');
}
},
onLoadSuccess: function(node, data) {
var id = $('input.easyui-combotree').val();
var v_t = $('input.easyui-combotree').combotree('tree');
if(id == null || id == 'undefined' || id.trim() == '') return;
//alert(id);
var t = v_t.tree('find',id); // 查找,并选中当前
if(t != null && t!=""){
v_t.tree('select', t.target);
}
},
onLoadError: function(){
$(this).append("<li>出错页面</li>");
}
});
}
一 page和report
<page id="edit_plansolution" js="/myproject/jqueryui/js/jquery-1.10.1.min.js,/myproject/jqueryui/js/jquery.easyui.min.js,/myproject/jqueryui/js/combotree.js"
css="/myproject/jqueryui/css/easyui.css,/myproject/jqueryui/css/icon.css" >
<report id="edit_detail" title="测试" onload="loadComboTree">
二、编辑列
<col column="eventype" label="事故类型:">
<inputbox jsvalidate="isNotEmpty(#label#列不能为空)" styleproperty="class='easyui-combotree' dataurl='SelectTree.jsp' valuefield='id' textfield='text' style='width:250px'" />
</col>
三、Service
Web.xml配置
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/naframework</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Spring配置
<?xml version="1.0"encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-lazy-init="true"> <!-- 数据源配置,在生产环境使用应用服务器的数据库连接池 -->
<bean id="springDSN"class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"value="java:comp/env/jdbc/naframework"/>
</bean> <bean id="jdbcTemplate"class="org.springframework.jdbc.core.JdbcTemplate"abstract="false" lazy-init="false"autowire="default"dependency-check="default">
<property name="dataSource">
<ref bean="springDSN"/>
</property>
</bean> <!-- 事务管理器配置,单数据源事务 -->
<bean id="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"ref="sessionFactory"/>
</bean>
</beans>
JAVA配置
privateJdbcTemplate jdbcT = (JdbcTemplate) SpringUtil.getBean("jdbcTemplate");
/**
* 拼接成json类型 事故类型
* @author 刘仁奎
* @return
*/
publicString getJSONData(){
// 查询一级节点
String sql="select * from category where categorytype='accidclass' and categorylevel='1' order by categorycode";
List list=jdbcT.queryForList(sql);
StringBuffer json=newStringBuffer("[");
String data="",d_2="";
if(list!=null&& list.size()>0){
for(inti=0; i<list.size();i++){
Map v_map = (Map)list.get(i);
json.append("{"id":""+v_map.get("CATEGORYCODE").toString().trim()+"",");
json.append(""text":""+v_map.get("CATEGORYNAME").toString().trim()+""");
if(v_map.get("CATEGORYLEVEL") != null&& v_map.get("CATEGORYLEVEL").toString().trim().equals("1")){// 判断是否是父节点,赋图标
// 拼接2级子节点
String sql_2="select * from category where categorytype='accidclass' and categorylevel='2' and parentcode='"+v_map.get("CATEGORYCODE")+"' order by categorycode";
List v_l=jdbcT.queryForList(sql_2);
if(v_l.size()>0){
json.append(","children":");
//System.out.println("********************"+sql_2+"***********************");
StringBuffer child_json=newStringBuffer("[");
for(intj=0; j<v_l.size();j++){
Map v_m = (Map) v_l.get(j);
child_json.append("{"id":""+v_m.get("CATEGORYCODE").toString().trim()+"",");
child_json.append(""text":""+v_m.get("CATEGORYNAME").toString().trim()+""},");
//System.out.println("_____子节点:_"+v_m.get("CATEGORYCODE")+"__"+v_m.get("CATEGORYNAME")+"___________");
}
if(child_json.lastIndexOf(",") != -1){
d_2 = child_json.substring(0,child_json.lastIndexOf(","))+"]},";
json.append(d_2);
}
}else{ // 如果没有子节点
json.append("},");
}
}
}
}
data=json.substring(0, json.length()-1)+"]";
System.out.println(data);
returndata;
}
我这里的Servlet使用了jsp代替
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.nasoft.jdbc.sysmanager.CategoryDao" %>
<%
/**
* 应急预案,事故类型下拉框树
*/
CategoryDao std = new CategoryDao(); //String json = std.getJSONData(); // String json="[{\"id\":1,\"text\":\"Folder1\",\"iconCls\":\"icon-ok\",\"children\":[{\"id\":2,\"text\":\"File1\"},{\"id\":3,\"text\":\"Folder2\",\"state\":\"open\",\"children\":[{\"id\":4,\"text\":\"File3\",\"iconCls\":\"icon-reload\"}]}]},{\"text\":\"Languages\",\"state\":\"closed\",\"children\":[{\"id\":\"j1\",\"text\":\"Java\"},{\"id\":\"j2\",\"text\":\"C#\"}]}]";
//System.out.println(json);
out.print(json); %>
Jquery UI 组合树 - ComboTree 集成Wabacus4.1 代码剖析的更多相关文章
- 表单(上)EasyUI Form 表单、EasyUI Validatebox 验证框、EasyUI Combobox 组合框、EasyUI Combo 组合、EasyUI Combotree 组合树
EasyUI Form 表单 通过 $.fn.form.defaults 重写默认的 defaults. 表单(form)提供多种方法来执行带有表单字段的动作,比如 ajax 提交.加载.清除,等等. ...
- jQuery UI Datepicker&Datetimepicker添加 时-分-秒 并且,判断
jQuery UI Datepicker时间(年-月-日) 相关代码: <input type="text" value="" name="ad ...
- combotree(组合树)的使用
一.前言: 组合树(combotree)把选择控件和下拉树结合起来.它与组合框(combobox)相似,不同的是把列表替换成树组件.组合树(combotree)支持带有用于多选的树状态复选框的树. 二 ...
- EasyUI组合树插件
一.引用CSS和JS <link href="~js/easyui/easyui.css" rel="stylesheet" type="tex ...
- 解决Select2控件不能在jQuery UI Dialog中不能搜索的bug
本文使用博客园Markdown编辑器进行编辑 1.问题呈现 项目中使用了jQuery UI的Dialog控件,一般用来处理需要提示用户输入或操作的简单页面.逻辑是修改一个广告的图片和标题. 效果截图如 ...
- jQuery UI Autocomplete是jQuery UI的自动完成组件(share)
官网:http://jqueryui.com/autocomplete/ 以下分享自:http://www.cnblogs.com/yuzhongwusan/archive/2012/06/04/25 ...
- 第四十四课:jQuery UI和jQuery easy UI
jQuery UI是jQuery官方提供的功能效果和UI样式.作为官方出的东西,它一直没有被人们看重,一是它没有datagrid,tree等UI库必备的东西,二是它修改太过频繁,体积庞大.其实它所有以 ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.4.Tabs控件
之前,我们已经介绍了 jQuery UI 库,CSS 框架.下面,我们将学习这些有增强可视化效果,高度可配置的用户交互组件. Tab 的特性是,点击 tab 后,会高亮该 tab,并显示他的关联con ...
- jQuery UI框架
jQuery UI框架 1.oschina开源社区-jQuery教程 2.jQuery PrimeUI(推荐) 3.弹出框.警告框.提示框.拖动支持.位置固定.选项卡切换 4.Bootstrap框架( ...
随机推荐
- String类的split方法以及StringTokenizer
split方法可以根据指定的表达式regex将一个字符串分割成一个子字符串数组. 它的参数有两种形式,也即:split(String regex)和split(String regex, int li ...
- configure脚本参数介绍
configure脚本有大量的命令行选项. 下面对每一个选项进行简略的介绍: --cache-file=FILE'configure' 会在你的系统上测试存在的特性(或者bug!).为了加速随后进行的 ...
- Eclipse 安装Activiti 插件失败解决方法
遇到的错误为:1.4.0' but it could not be found等.
- Hausdorff距离
Hausdorff距离是描述两组点集之间相似程度的一种量度,它是两个点集之间距离的一种定义形式:假设有两组集合A={a1,…,ap},B={b1,…,bq},则这两个点集合之间的Hausdorff距离 ...
- More on 1Password’s Components
Stefan van As of 1Password fame sent me a more exhaustive list of the libraries and tools used in 1P ...
- Fast UI Draw (Intel出品)
Fast UI Draw in a library that provides a higher performance Canvas interface. It is designed so tha ...
- RecyclerView一个奇怪的npe异常
java.lang.NullPointerException at android.support.v7.widget.RecyclerView.computeVerticalScrollOffset ...
- 手势识别官方教程(6)识别拖拽手势用GestureDetector.SimpleOnGestureListener和onTouchEvent
三种现实drag方式 1,在3.0以后可以直接用 View.OnDragListener (在onTouchEvent中调用某个view的startDrag()) 2,onTouchEvent() ...
- 使用GDI+ DrawDriverString实现行距及字符间距控制
主要是要将一个标题和几段文字绘制到固定大小的图片上,如果一张放不下就生成多张.在使用DrawString是发现无法控制行距 namespace TibetTest { public class ...
- a++与=++a的区别
//a++;//a=a+1; // ++a;//a=a+1; //Console.WriteLine(a++);// Console.WriteL ...