`

easyui中combotree异步加载的一些问题

阅读更多

1. 先是前台js请求

  
    // 上级部门下拉列表
	$('#department').combotree({
		url : 'departmentMaintainAction!queryDepartmentTree.action',
		valueField : 'id',
		textField : 'text',
		required : true,
		editable : false,
		onClick : function(node) {
			if (node.attributes.url) {
				insertTab(node);
			}
		},
//全部展开
		onLoadSuccess : function(node, data) {
			var t = $(this);
			if (data) {
				$(data).each(function(index, d) {
					if (this.state == 'closed') {
						t.tree('expandAll');
					}
				});
			}
		}
	});
     
   


2. 后台json

  
        
	JSONArray jsonArrayIn = new JSONArray();
		for (Department department : departmentList) {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("id", department.getDptId());
			jsonObject.put("text", department.getBmmc());
       //[color=blue] 注意这里的state很重要,combotree就是根据state
       // 的值来判断是否向后台再次请求子节点数据,       
       // 同时它还向后台传递了该节点的id值,作为后台查询依据[/color]

			if(department.getIsLeaf().equals("0")){
				jsonObject.put("state", "closed");
			}else {
				jsonObject.put("state", "open");
			}
			
			jsonArrayIn.put(jsonObject);
		}
   


3. 后台数据查询需要注意的是

  
        //combotree自动返回的父节点id,这是关键
         String id = request.getParameter("id");
         if(id != null){
	   department.setDptId(id);
	  }    
   

  
    //这是dao中的处理
    if(department.getDptId() == null){
         sql.append("and parent_id is null order by seq asc");
 	 query = this.getSession().createQuery(sql.toString());
     }else{
         sql.append("and parent_id = :parent_id order by seq asc");
    	 query = this.getSession().createQuery(sql.toString());
         query.setParameter("parent_id", department.getDptId());
     }
  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics