action:
// 形成市场客户公司的树节点 public String marketjson() throws Exception { try { List<Org> dlist = bdao.list("from Org d where d.flag=3"); StringBuffer str = new StringBuffer(); str.append("["); for (int j = 0; j < dlist.size(); j++) { Long pId = 0L; if (dlist.get(j).getSuperOrg() != null && dlist.get(j).getSuperOrg().getOrgId() != null) { pId = dlist.get(j).getSuperOrg().getOrgId(); } if (j == dlist.size() - 1) { str.append("{id:" + dlist.get(j).getOrgId() + ",pId:" + pId + ",name:'" + dlist.get(j).getName() + "',t:'" + dlist.get(j).getName() + "'}"); } else { str.append("{id:" + dlist.get(j).getOrgId() + ",pId:" + pId + ",name:'" + dlist.get(j).getName() + "',t:'" + dlist.get(j).getName() + "'},"); } } str.append("]"); outJson(str.toString()); } catch (Exception e) { e.printStackTrace(); } return "ajax"; }
public static void outJson(String str) { try { ActionContext.getContext().put("json", str); } catch (Exception e) { e.printStackTrace(); } }
jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="/templates/taglibs.jsp"%> <link rel="stylesheet" href="${basePath}/css/zTreeStyle.css" type="text/css">
<SCRIPT LANGUAGE="JavaScript"> var setting = { data : { key : { title : "t" }, simpleData : { enable : true } }, callback : { onClick : onClick } }; function onClick(event, treeId, treeNode, clickFlag) { var orgId = treeNode.id; var orgName = treeNode.name; $('#tabs1').tabs(); var corner_top=$('#tabs1').find(".ui-tabs-selected"); var iframeId = corner_top.find("a").attr("href"); var idoc = $($(iframeId).attr("contentDocument")); idoc.find("#orgName").val(orgName); idoc.find("#orgId").val(orgId); idoc.find("#contactName").val(orgName); idoc.find("#contactId").val(orgId); idoc.find("#caseBean.assured.name").val(orgName); idoc.find("#caseBean.assured.orgId").val(orgId); idoc.find("#queryBtn").click(); var href1 = "<s:property value='basePath'/>contacts/orgMgr!orgOrgShow?orgId=" + orgId; $("#jbxxFrame").attr("src", href1); } function showFun() { $.ajax({ type : 'get', url : "<s:property value='basePath'/>contacts/orgMgr!marketjson" + "?a=" + new Date(), success : function(data) { $.fn.zTree.init($("#treeDemo"), setting, eval("(" + data.valueOf() + ")")); } }); } $(function() { $("#tabs1").tabs(); }); /* function ajaxSubmit(form){ var str = $(form).serialize(); var url=$(form).attr("action"); $.ajax({type: "POST",url: url,data: str,success: function(msg){ var $tabs = $('#tabs1').tabs(); var selected = $tabs.tabs('option', 'selected'); var tabBody=$("#ui-tabs-"+(selected+1)); tabBody.empty(); tabBody.html(msg); } }); return false; } */ function searchNode() { var texts = document.getElementById("companyName").value; var text = $.trim(texts); if(text != ""){ var nodes = []; var treeObj = $.fn.zTree.getZTreeObj("treeDemo"); treeObj.cancelSelectedNode(); nodes = treeObj.getNodesByParamFuzzy("name", text); if (nodes.length>0) { for(var i=0;i<nodes.length;i++){ treeObj.selectNode(nodes[i],true); } } } }
</SCRIPT> <body onload="showFun()"> <div class="queryPanel"> <div class="panel-title"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="3%"><img src="${ctx}/images/form/tu5.gif" width="30" height="33" /></td> <td width="97%">市场客户客户管理</td> </tr> </table> </div> <div class="content_wrap"> <div class="zTreeDemoBackground left"> <br/> <input type="text" id="companyName" style="width: 180px;"/> <button type="button" id="queryBtn" onclick="searchNode()" >查询</button> <ul id="treeDemo" class="ztree"></ul> </div> <div class="content_wrap right" id="tabs1"> <ul> <li id="jbxx"><a id="jbxxSrc" href="#jbxxFrame">查询公司</a></li> <li id="lxr"><a id="lxrSrc" href="#lxrFrame">联系人</a></li> <li id="xm"><a id="xmSrc" href="#xmFrame">项目</a></li> <li id="sp"><a id="spSrc" href="#spFrame">索赔</a></li> <li id="px"><a id="pxSrc" href="#pxFrame">培训</a></li> <li id="qt"><a id="qtSrc" href="#qtFrame">其他</a></li> </ul> <iframe id="jbxxFrame" height="400px;" width="100%;" src="<s:property value='basePath'/>contacts/orgMgr!orgOrgShow?orgId=1570"></iframe> <iframe id="lxrFrame" height="400px;" width="100%;" src="<s:property value='basePath'/>contacts/orgMgr!listContacts?orgId="></iframe> <iframe id="xmFrame" height="400px;" width="100%;" src="<s:property value='basePath'/>contacts/orgMgr!listProjects"></iframe> <iframe id="spFrame" height="400px;" width="100%;" src="<s:property value='basePath'/>contacts/orgMgr!listCase?orgId=1570"></iframe> <iframe id="pxFrame" height="400px;" width="100%;" src="http://www.baidu.com"></iframe> <iframe id="qtFrame" height="400px;" width="100%;" src="/www.baidu.com"></iframe> </div> </div> </div> </body>