Jquery easyui 实现动态树
作者:bea
在上篇文章给大家介绍了jquery中EasyUI实现异步树,本文给大家介绍jquery easyui实现动态树。 首先是在jsp页面中引入相关的js文件 在body中加入流程列表,通过后天拼接json数据 具体内容请看下面代码详情吧。 首选在jsp页面中引入相关的js <link rel="stylesheet" type="text/css" href="<%=path %>/css/jquery_easyui/themes/default/easyu
在上篇文章给大家介绍了jquery中EasyUI实现异步树,本文给大家介绍jquery easyui实现动态树。
首先是在jsp页面中引入相关的js文件 在body中加入流程列表,通过后天拼接json数据 具体内容请看下面代码详情吧。
首选在jsp页面中引入相关的js
<link rel="stylesheet" type="text/css" href="<%=path %>/css/jquery_easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/css/jquery_easyui/themes/icon.css">
<script type="text/javascript" src="<%=path %>/js/jquery_easyui/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/jquery_easyui/jquery.easyui.min.js"></script>
添加script
<script>
$(function(){
$('#tt2').tree({
checkbox: false,
url: '<%=path%>/formconfig/loadWfNodes.do',
onBeforeExpand: function(node){
$('#tt2').tree('options').url = '<%=path%>/formconfig/loadWfNodes.do?wfId='+node.id;
}
});
});
</script>
在body中加入
<body>
<ul id="tt2">
<li state="closed" id='0'><span>流程列表</span></li>
</ul>
</body>
后台拼接json数据
package com.aegon_cnooc.oa.formconfig.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.aegon_cnooc.framework.base.action.BaseAction;
import com.aegon_cnooc.oa.formconfig.service.FormConfigService;
import com.aegon_cnooc.oa.ibatis.to.TuOafWfTO;
import com.aegon_cnooc.oa.ibatis.to.TuOafWfnodesTO;
import com.aegon_cnooc.util.StringUtil;
/**
* 加载流程下的节点的名称
* @Author: liuxinghui
* @Date: 2011-9-8
* @Version: 2.0
* @Despcrition:
*/
public class LoadWfNodesAction extends BaseAction{
private FormConfigService formConfigService;
public ActionForward executeAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String wfId=request.getParameter("wfId");
String jsonstr = "[";
if(StringUtil.isNotEmpty(wfId)&&"0".equals(wfId)){
List wfList=formConfigService.findWf();
for(int i=0;i<wfList.size();i++){
TuOafWfTO wfTo=(TuOafWfTO)wfList.get(i);
jsonstr=jsonstr+
"{
" +
" "id":"+wfTo.getWfid()+",
" +
" "text":"<a href='javaScript:void(0)' target='mainFrame'>"+wfTo.getWfname()+"</a>",
" +
" "state":"closed"
" +
" },";
}
int end=jsonstr.length()-1;//去掉最后一个逗号
String json=jsonstr.substring(0,end);
json=json+"]";
response.setContentType("application/json;charset=gbk");
response.setCharacterEncoding("gbk");
PrintWriter pw = response.getWriter();
pw.write(json);
pw.flush();
}else{
List wfNodes=formConfigService.findWfNodesById(wfId);
for(int i=0;i<wfNodes.size();i++){
TuOafWfnodesTO wfNodesTo=(TuOafWfnodesTO)wfNodes.get(i);
jsonstr=jsonstr+
"{
" +
" "id":"+wfNodesTo.getNodeid()+",
" +
" "text":"<a href='" + request.getContextPath()+
"/formconfig/loadGroupByWfIdAndNodeId.do?wfId="+wfId+"&nodeId="+wfNodesTo.getNodeid()+"' target='mainFrame'>"+wfNodesTo.getGenstepname()+"("+wfNodesTo.getNodeid()+")</a>",
" +
" "state":"closed"
" +
" },";
}
int end=jsonstr.length()-1;//去掉最后一个逗号
String json=jsonstr.substring(0,end);
json=json+"]";
response.setContentType("application/json;charset=gbk");
response.setCharacterEncoding("gbk");
PrintWriter pw = response.getWriter();
pw.write(json);
pw.flush();
}
return null;
}
public void setFormConfigService(FormConfigService formConfigService) {
this.formConfigService = formConfigService;
}
}
下面一段代码是EasyUI Jquery 动态加载树,点击节点加载
<script type="text/javascript">
$(function() {
$(document).ready(function() {
$.post("./test/tree.action", {}, function(json) {
$("#tt").tree({
data : json.itemsList,
onClick : function(node) {
$.post("./test/tree.action", {
"id" : node.id
}, function(json) {
$('#tt').tree('append', {
parent : node.target,
data : json.data
});
}, "json");
}
});
}, "json");
});
});
</script>
</head>
<body>
<ul id="tt"></ul>
</body>
有用 | 无用
首先是在jsp页面中引入相关的js文件 在body中加入流程列表,通过后天拼接json数据 具体内容请看下面代码详情吧。
首选在jsp页面中引入相关的js
<link rel="stylesheet" type="text/css" href="<%=path %>/css/jquery_easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/css/jquery_easyui/themes/icon.css">
<script type="text/javascript" src="<%=path %>/js/jquery_easyui/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/jquery_easyui/jquery.easyui.min.js"></script>
添加script
<script>
$(function(){
$('#tt2').tree({
checkbox: false,
url: '<%=path%>/formconfig/loadWfNodes.do',
onBeforeExpand: function(node){
$('#tt2').tree('options').url = '<%=path%>/formconfig/loadWfNodes.do?wfId='+node.id;
}
});
});
</script>
在body中加入
<body>
<ul id="tt2">
<li state="closed" id='0'><span>流程列表</span></li>
</ul>
</body>
后台拼接json数据
package com.aegon_cnooc.oa.formconfig.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.aegon_cnooc.framework.base.action.BaseAction;
import com.aegon_cnooc.oa.formconfig.service.FormConfigService;
import com.aegon_cnooc.oa.ibatis.to.TuOafWfTO;
import com.aegon_cnooc.oa.ibatis.to.TuOafWfnodesTO;
import com.aegon_cnooc.util.StringUtil;
/**
* 加载流程下的节点的名称
* @Author: liuxinghui
* @Date: 2011-9-8
* @Version: 2.0
* @Despcrition:
*/
public class LoadWfNodesAction extends BaseAction{
private FormConfigService formConfigService;
public ActionForward executeAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String wfId=request.getParameter("wfId");
String jsonstr = "[";
if(StringUtil.isNotEmpty(wfId)&&"0".equals(wfId)){
List wfList=formConfigService.findWf();
for(int i=0;i<wfList.size();i++){
TuOafWfTO wfTo=(TuOafWfTO)wfList.get(i);
jsonstr=jsonstr+
"{
" +
" "id":"+wfTo.getWfid()+",
" +
" "text":"<a href='javaScript:void(0)' target='mainFrame'>"+wfTo.getWfname()+"</a>",
" +
" "state":"closed"
" +
" },";
}
int end=jsonstr.length()-1;//去掉最后一个逗号
String json=jsonstr.substring(0,end);
json=json+"]";
response.setContentType("application/json;charset=gbk");
response.setCharacterEncoding("gbk");
PrintWriter pw = response.getWriter();
pw.write(json);
pw.flush();
}else{
List wfNodes=formConfigService.findWfNodesById(wfId);
for(int i=0;i<wfNodes.size();i++){
TuOafWfnodesTO wfNodesTo=(TuOafWfnodesTO)wfNodes.get(i);
jsonstr=jsonstr+
"{
" +
" "id":"+wfNodesTo.getNodeid()+",
" +
" "text":"<a href='" + request.getContextPath()+
"/formconfig/loadGroupByWfIdAndNodeId.do?wfId="+wfId+"&nodeId="+wfNodesTo.getNodeid()+"' target='mainFrame'>"+wfNodesTo.getGenstepname()+"("+wfNodesTo.getNodeid()+")</a>",
" +
" "state":"closed"
" +
" },";
}
int end=jsonstr.length()-1;//去掉最后一个逗号
String json=jsonstr.substring(0,end);
json=json+"]";
response.setContentType("application/json;charset=gbk");
response.setCharacterEncoding("gbk");
PrintWriter pw = response.getWriter();
pw.write(json);
pw.flush();
}
return null;
}
public void setFormConfigService(FormConfigService formConfigService) {
this.formConfigService = formConfigService;
}
}
下面一段代码是EasyUI Jquery 动态加载树,点击节点加载
<script type="text/javascript">
$(function() {
$(document).ready(function() {
$.post("./test/tree.action", {}, function(json) {
$("#tt").tree({
data : json.itemsList,
onClick : function(node) {
$.post("./test/tree.action", {
"id" : node.id
}, function(json) {
$('#tt').tree('append', {
parent : node.target,
data : json.data
});
}, "json");
}
});
}, "json");
});
});
</script>
</head>
<body>
<ul id="tt"></ul>
</body>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jQuery EasyUI 布局之动态添加tabs标签页
- 如何使用jquery easyui创建标签组件
- JavaScript严格模式详解
- 每天一篇javascript学习小结(String对象)
- 跟我学习javascript的执行上下文
- 跟我学习JScript的Bug与内存管理
- 跟我学习javascript的循环
- js操作table元素实现表格行列新增、删除技巧总结
- 跟我学习javascript的for循环和for...in循环
- js实现模拟银行卡账号输入显示效果
- 跟我学习javascript的prototype原型和原型链
- 超精准的javascript验证身份证号的具体实现方法
- javascript中checkbox使用方法简单实例演示
- javascript下拉列表中显示树形菜单的实现方法
- JS封装cookie操作函数实例(设置、读取、删除)
- jquery可定制的在线UEditor编辑器
- JS实现选项卡实例详解
- 基于Jquery代码实现支持PC端手机端幻灯片代码
- 举例说明如何为JavaScript的方法参数设置默认值