之前使用jeecg集成框架做过一个项目
这里说说框架中树(tree)字段的扩展,在jeecg集成框架中,树列字段默认只能显示两列,如下图所示:
通常情况下前后台代码格式如下所示
前台代码获取(部分)
后台代码(部分)
/**
* 部门列表,树形展示
* @param request
* @param response
* @param treegrid
* @return
*/
@RequestMapping(params = "departgrid")
@ResponseBody
public List departgrid(TSDepart tSDepart,HttpServletRequest request, HttpServletResponse response, TreeGrid treegrid) {
CriteriaQuery cq = new CriteriaQuery(TSDepart.class);
if("yes".equals(request.getParameter("isSearch"))){
treegrid.setId(null);
tSDepart.setId(null);
}
if(null != tSDepart.getDepartname()){
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tSDepart);
}
if (treegrid.getId() != null) {
cq.eq("TSPDepart.id", Integer.parseInt(treegrid.getId()));
}
if (treegrid.getId() == null) {
cq.isNull("TSPDepart.id");
}
cq.add();
List departList =null;
departList = systemService.getListByCriteriaQuery(cq, false);
if(departList.size() == 0 && tSDepart.getDepartname() != null){
cq = new CriteriaQuery(TSDepart.class);
TSDepart parDepart = new TSDepart();
tSDepart.setTSPDepart(parDepart);
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tSDepart);
departList = systemService.getListByCriteriaQuery(cq, false);
}
List treeGrids = new ArrayList();
TreeGridModel treeGridModel = new TreeGridModel();
treeGridModel.setTextField("departname");
treeGridModel.setParentText("TSPDepart_departname");
treeGridModel.setParentId("TSPDepart_id");
treeGridModel.setSrc("description");
treeGridModel.setIdField("id");
treeGridModel.setChildList("TSDeparts");
treeGrids = systemService.treegrid(departList, treeGridModel);
return treeGrids;
}
其实扩展方法很简单,因为 作者已经帮我们留了扩展的方法了。捕捉树列表响应的数据如下(部分响应数据):
[
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "中联总部",
"id": "1",
"state": "closed",
"attributes": null,
"text": "中联总部",
"code": null
},
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "混凝土机械国际管理公司",
"id": "2",
"state": "closed",
"attributes": null,
"text": "混凝土机械国际管理公司",
"code": null
},
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "工程起重机公司",
"id": "5",
"state": "closed",
"attributes": null,
"text": "工程起重机公司",
"code": null
},
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "建筑起重机公司",
"id": "6",
"state": "closed",
"attributes": null,
"text": "建筑起重机公司",
"code": null
}
]
即扩展树字段的方法原理就是后台添加attribute并把需要在前台显示的值存进去,前台取attribute的值。代码如下
后台代码(因为没有扩展上面机构tree代码,我挑选了其他树扩展的代码)
Map map;
for (int i = 0; i < treeGrids.size(); i++) {
map = new HashMap();
map.put("description", assetDepreciationList.get(i).getDescription());
treeGrids.get(i).setAttributes(map);
}
把需要扩展显示的字段put进去,上面我增加了一个显示字段,如果有多个同样put多个进去。
前台jsp代码
写法一
写法二
function getDescription(value, rec, index) {
return rec.attributes.descripition;
}
以上就是jeecg中树的列显示字段扩展,如果有多个需要扩展就根据以上格式编写多个即可。