EasyUI 编写实体类树状选择器
<%@ page contentType="text/html;charset=UTF-8"%> <%@ include file="/WEB-INF/views/include/taglib.jsp"%> <meta name="decorator" content="index" /> <body> <div class="portlet-body"> <table id="xxxdg" height="auto" width="100%"></table> </div> <script type="text/javascript"> var trees = '${fns:getXXXListByTree()}' var dg = $('#xxxdg').treegrid({ method: 'post', rownumbers: true, idField: 'id', treeField: 'name', height:'500px', singleSelect : false, columns:[[ {field:'id',title:'编号',hidden:true}, {field:'name',title:'名称',width:240,sortable:true,formatter:formatterData}, {field:'description',title:'描述',width:150,align:'center'}, ]] }); //变量trees的值是符合treegrid要求的json格式的字符串 var data =$.parseJSON('{"total":0,"rows":'+ trees +'}'); dg.treegrid('loadData', data); //将数据绑定到treegrid function formatterData(value,rowData,rowIndex){ //rowData是当节点的数据集,children表示其分支,如果!=undefined则表示当前节点有分支,由于这个树只有两层,也表示它就是父节点。如果是父节点,就不在后面加checkbox if(rowData.children != undefined){ return rowData.name; }else{ //在调用当前jsp时用url传值的形式传过来的sortids变量 var sortIds = '${param.sortIds}'; var checked = ""; if(sortIds!="") { if(sortIds.indexOf(rowData.id) > -1){ checked = "checked='checked'"; } } //将checkbox动态拼在名称前 return "<input "+checked+"type='checkbox' id='ids_"+rowData.id+"' value='values_"+rowData.name+"'>" + rowData.name; } } </script> </body>