easyui中combotree加载数据处理

来源:互联网 发布:周立功单片机笔试题目 编辑:程序博客网 时间:2024/05/16 23:55

前台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"}]}]



1 0