• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
zziy的java笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
Easyui 异步树的实现

网上最多的onBeforeExpand 可用,因为后台代码没写对导致树形结构重复加载数据

前端代码: 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3     <div>
 4         <table cellpadding="5">
 5             <tr>
 6                 <td height="300px"><ul id="diseaseNameTree" class="easyui-tree"></ul>
 7                 </td>
 8             </tr>
 9         </table>
10     </div>
11 <script>
12     $('#diseaseNameTree').tree({
13         url : getServer_context() + '/api/patient/getDiseaseNameTree?Id=',
14         onBeforeExpand : function(node, param) {
15             console.log('ID=' + node.id);
16             console.log('length=' + node.id.length);
17             $('#diseaseNameTree').tree('options').url = getServer_context() + '/api/patient/getDiseaseNameTree?Id=' + node.id;
18         }
19     })
20                     
21     function searchICD10ByPinyin() {
22         var pinyin = $('#ICD10Pinyin').val();
23         console.log(pinyin);
24         if (pinyin == null || pinyin == "") {
25             $('#diseaseNameTree').tree('reload');
26         } else {
27             console.log('000');
28             $('#diseaseNameTree').tree({
29                 url: getServer_context() + '/api/patient/getDiseaseNameByPinyin?Pinyin=' + pinyin
30             });
31         }
32 
33     }
34 </script>

 

后台代码:

 1     public JSONArray getDiseaseNameTreeData(String Id) throws RecordNotFoundException {
 2         JSONArray jsonArray = new JSONArray();
 3         JSONArray childrenArray = new JSONArray();
 4         JSONArray grandChildrenArray = new JSONArray();
 5         JSONObject parentObject = new JSONObject();
 6         JSONObject childrenObject = new JSONObject();
 7         JSONObject grandChildrenObject = new JSONObject();
 8         
 9         if(Id == null || "".equals(Id)) {
10             Iterable<SsIcd10> parentList = ssICD10Dao.getDiseaseNameParent();
11             for(SsIcd10 parent : parentList) {
12                 parentObject.clear();
13                 parentObject.put("id", parent.getFicd10());
14                 parentObject.put("text", parent.getFdesc());
15                 parentObject.put("state", "closed");
16                 jsonArray.add(parentObject);
17             }
18             return jsonArray;
19         } else if (Id.length() == 3){
20             Iterable<SsIcd10> childrenList = ssICD10Dao.gettDiseaseNameChildren(Id);
21             for(SsIcd10 child : childrenList) {
22                 childrenObject.clear();
23                 childrenObject.put("id", child.getFicd10());
24                 childrenObject.put("text", child.getFdesc());
25                 childrenObject.put("state", ssICD10Dao.hasGrandChildren(child.getFicd10()) > 0 ? "closed" : "open");
26                 childrenArray.add(childrenObject);
27             }
28             return childrenArray;
29         } else {
30             Iterable<SsIcd10> grandChildrenList = ssICD10Dao.gettDiseaseNameGrandChildren(Id);
31             for(SsIcd10 grandChild : grandChildrenList) {
32                 grandChildrenObject.clear();
33                 grandChildrenObject.put("id", grandChild.getFicd10());
34                 grandChildrenObject.put("text", grandChild.getFdesc());
35                 grandChildrenArray.add(grandChildrenObject);
36             }
37             return grandChildrenArray;
38         }

 

逻辑写的很傻,还没想出来怎么写更好的

 1     public JSONArray getDiseaseNameTreeByPinyin(String Pinyin) throws RecordNotFoundException {
 2         JSONArray jsonArray = new JSONArray();
 3         JSONArray childrenArray = new JSONArray();
 4         JSONArray grandChildrenArray = new JSONArray();
 5         JSONObject parentObject = new JSONObject();
 6         JSONObject childrenObject = new JSONObject();
 7         JSONObject grandChildrenObject = new JSONObject();
 8         Iterable<SsIcd10> list = ssICD10Dao.getDiseaseNameDataByPinyin(Pinyin);
 9         for(SsIcd10 ssIcd10 : list) {
10             if(ssIcd10.getFicd10().length() == 3) {
11                 parentObject.clear();
12                 parentObject.put("id", ssIcd10.getFicd10());
13                 parentObject.put("text", ssIcd10.getFdesc());
14                 Iterable<SsIcd10> children =  ssICD10Dao.getDiseaseNameChildrenByPinyin(ssIcd10.getFicd10(), Pinyin);
15                 if(children != null) {
16                     childrenArray.clear();
17                     for(SsIcd10 child : children) {
18                         childrenObject.clear();
19                         childrenObject.put("id", child.getFicd10());
20                         childrenObject.put("text", child.getFdesc());
21                         Iterable<SsIcd10> grandChildren = ssICD10Dao.getDiseaseNameGrandChildrenByPinyin(child.getFicd10(), Pinyin);
22                         if(grandChildren != null) {
23                             grandChildrenArray.clear();
24                             for(SsIcd10 grandChild : grandChildren) {
25                                 grandChildrenObject.clear();
26                                 grandChildrenObject.put("id", grandChild.getFicd10());
27                                 grandChildrenObject.put("text", grandChild.getFdesc());
28                                 grandChildrenArray.add(grandChildrenObject);
29                             }
30                             childrenObject.put("children", grandChildrenArray);
31                         }
32                         childrenArray.add(childrenObject);
33                     }
34                     parentObject.put("children", childrenArray);
35                 }
36                 jsonArray.add(parentObject);
37             } else if (ssIcd10.getFicd10().length() > 3 && ssIcd10.getFicd10().length() <= 6) {
38                 if(ssICD10Dao.hasParent(ssIcd10.getFicd10().substring(0, 3), Pinyin) == 0) {
39                     parentObject.clear();
40                     parentObject.put("id", ssIcd10.getFicd10());
41                     parentObject.put("text", ssIcd10.getFdesc());
42                     Iterable<SsIcd10> grandChildren = ssICD10Dao.getDiseaseNameGrandChildrenByPinyin(ssIcd10.getFicd10(), Pinyin);
43                     if(grandChildren != null) {
44                         grandChildrenArray.clear();
45                         for(SsIcd10 grandChild : grandChildren) {
46                             grandChildrenObject.clear();
47                             grandChildrenObject.put("id", grandChild.getFicd10());
48                             grandChildrenObject.put("text", grandChild.getFdesc());
49                             grandChildrenArray.add(grandChildrenObject);
50                         }
51                         parentObject.put("children", grandChildrenArray);
52                     }
53                     jsonArray.add(parentObject);
54                 }
55             } else {
56                 if(ssICD10Dao.hasParent(ssIcd10.getFicd10().substring(0, 3), Pinyin) == 0 
57                         && ssICD10Dao.hasChildren(ssIcd10.getFicd10().substring(0, 6), Pinyin) == 0) {
58                     parentObject.clear();
59                     parentObject.put("id", ssIcd10.getFicd10());
60                     parentObject.put("text", ssIcd10.getFdesc());
61                     jsonArray.add(parentObject);
62                 }
63             }
64         }
65         return jsonArray;
66         
67     }

 

posted on 2016-05-18 17:49  zziy  阅读(1830)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3