Jquery easyui 實(shí)現(xiàn)動態(tài)樹
在上篇文章給大家介紹了jquery中EasyUI實(shí)現(xiàn)異步樹,本文給大家介紹jquery easyui實(shí)現(xiàn)動態(tài)樹。
首先是在jsp頁面中引入相關(guān)的js文件
在body中加入流程列表,通過后天拼接json數(shù)據(jù)
具體內(nèi)容請看下面代碼詳情吧。
首選在jsp頁面中引入相關(guān)的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數(shù)據(jù)
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;
/**
* 加載流程下的節(jié)點(diǎn)的名稱
* @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+
"{\n" +
" \"id\":"+wfTo.getWfid()+",\n" +
" \"text\":\"<a href='javaScript:void(0)' target='mainFrame'>"+wfTo.getWfname()+"</a>\",\n" +
" \"state\":\"closed\"\n" +
" },";
}
int end=jsonstr.length()-1;//去掉最后一個(gè)逗號
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+
"{\n" +
" \"id\":"+wfNodesTo.getNodeid()+",\n" +
" \"text\":\"<a href='" + request.getContextPath()+
"/formconfig/loadGroupByWfIdAndNodeId.do?wfId="+wfId+"&nodeId="+wfNodesTo.getNodeid()+"' target='mainFrame'>"+wfNodesTo.getGenstepname()+"("+wfNodesTo.getNodeid()+")</a>\",\n" +
" \"state\":\"closed\"\n" +
" },";
}
int end=jsonstr.length()-1;//去掉最后一個(gè)逗號
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 動態(tài)加載樹,點(diǎn)擊節(jié)點(diǎn)加載
<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>
相關(guān)文章
jQuery實(shí)現(xiàn)等比例縮放大圖片讓大圖片自適應(yīng)頁面布局
遇到大圖片將頁面容器“撐破”的情況在進(jìn)行頁面布局時(shí)會經(jīng)常遇到吧,在本文將為大家講述使用jQuery實(shí)現(xiàn)按比例縮放大圖片,讓大圖片自適應(yīng)頁面布局2013-10-10
jquery下為Event handler傳遞動態(tài)參數(shù)的代碼
在jquery cook book里看到一篇給event handler傳遞動態(tài)參數(shù)的文章 感覺挺實(shí)用的 跟大家分享下2011-01-01
jquery操作復(fù)選框(checkbox)的12個(gè)小技巧總結(jié)
本篇文章主要是對jquery操作復(fù)選框(checkbox)的12個(gè)小技巧進(jìn)行了總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
基于Jquery代碼實(shí)現(xiàn)手風(fēng)琴菜單
這篇文章主要介紹了基于Jquery代碼實(shí)現(xiàn)手風(fēng)琴菜單,代碼簡單易懂,需要的朋友參考下2015-11-11
jQuery插件artDialog.js使用與關(guān)閉方法示例
這篇文章主要介紹了jQuery插件artDialog.js使用與關(guān)閉方法,結(jié)合具體實(shí)例形式分析了jQuery彈出窗口插件artDialog.js的簡單使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-10-10

