easyui中combotree加载数据处理

前台js处理:

$('#drugClass').combotree({
    valueField: 'id',
    textField: 'text',
    method: 'get',
    animate: true,
    editable:'true',
    mode:'remote',
    url: '/service/drug-price/find',
    onSelect: function (row) {
        $("#drugCode").combogrid('clear');
        var classCode = row.id;
        $.get(basePath + "/drug-price/findDrugDictByClass?classCode=" + classCode + "&orgId=" + config.org_Id, function (data) {
            //定义药品名称
            $("#drugCode").combogrid("grid").datagrid("loadData", data);
        });
    }
})
 
后台处理数据:
@GET
@Path("find")
public List<CombotreeUntils> LinqJson() {
    String parientId = null;
    List<CombotreeUntils> list = LinqJsonTree(parientId);
    return list;
}


//查询并且构建combotree的数据
public List<CombotreeUntils> LinqJsonTree(String parientId) {
    List<DrugClassDict> drugClassDicts = null;
    List<CombotreeUntils> jsonData = new ArrayList<CombotreeUntils>();
    //判断药品的代码是否为2位
    if (StringUtils.isNotBlank(parientId) && parientId.length() == 2) {
        drugClassDicts = drugClassDictApi.findClassDictByParentId(parientId);
    }else{
        drugClassDicts = drugClassDictApi.findClassDictByParentId("*");
    }
    CombotreeUntils combotreeUntils = null;
    for (int i = 0; i < drugClassDicts.size(); i++) {
        combotreeUntils = new CombotreeUntils();
        combotreeUntils.setId(drugClassDicts.get(i).getClassCode());
        combotreeUntils.setText(drugClassDicts.get(i).getClassName());
        combotreeUntils.setState("closed");  //在加载出全部数据后,将节点关闭

        if (drugClassDicts.get(i).getClassCode().length() == 5) {
            combotreeUntils.setChildren(new ArrayList<CombotreeUntils>());
        } else {
            combotreeUntils.setChildren(LinqJsonTree(drugClassDicts.get(i).getClassCode()));
        }
        jsonData.add(combotreeUntils);
    }
    return jsonData;
}
所用到的类:
public class CombotreeUntils {
    public String id;
    public String text;
    public List<CombotreeUntils> children ;
    public String  parentId ;
    public  String state;
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public List<CombotreeUntils> getChildren() {
        return children;
    }

    public void setChildren(List<CombotreeUntils> children) {
        this.children = children;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }
}
easyui中combotree所需要用到的数据格式为:
{
	"id":1,
	"text":"My Documents",
	"children":[{
		"id":11,
		"text":"Photos",
		"state":"closed",
		"children":[{
			"id":111,
			"text":"Friend"
		},{
			"id":112,
			"text":"Wife"
		},{
			"id":113,
			"text":"Company"
		}]
	},{
		"id":12,
		"text":"Program Files",
		"children":[{
			"id":121,
			"text":"Intel"
		},{
			"id":122,
			"text":"Java",
			"attributes":{
				"p1":"Custom Attribute1",
				"p2":"Custom Attribute2"
			}
		},{
			"id":123,
			"text":"Microsoft Office"
		},{
			"id":124,
			"text":"Games",
			"checked":true
		}]
	},{
		"id":13,
		"text":"index.html"
	},{
		"id":14,
		"text":"about.html"
	},{
		"id":15,
		"text":"welcome.html"
	}]
}]


 
 
 
 
 
 
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值