81,092
社区成员
发帖
与我相关
我的任务
分享
public class ResourceVO extends BasBizVO {
private static final long serialVersionUID = 1L;
private long id ;
private String name; // 名称
private String url;
private String description; //描述
private String icon;
private Long pid;
private String pname;
private String seq; //排序
private Integer state;
private Integer resourcetype; //是否默认
private Integer systemtype;
<select id="queryResourceInfo"
resultClass="com.file.sys.vo.ResourceVO"
parameterClass="java.util.HashMap">
SELECT
a.id ,
a.name,
a.url,
a.description,
a.icon,
a.pid,
b.name as pname,
a.seq,
a.state,
a.resourcetype,
a.systemtype
FROM sys_resource as a
left join sys_resource as b on a.pid=b.id
WHERE 1=1
<dynamic prepend="AND">
<isNotEmpty prepend="AND" property="id">
<![CDATA[a.id = #id#]]>
</isNotEmpty>
<isNotEmpty prepend="AND" property="name">
<![CDATA[a.name LIKE '%$name$%']]>
</isNotEmpty>
<isNotEmpty prepend="AND" property="resourcetype">
<![CDATA[a.resourcetype = #resourcetype#]]>
</isNotEmpty>
<isNotEmpty prepend="AND" property="state">
<![CDATA[a.state = #state#]]>
</isNotEmpty>
<isNotEmpty prepend="AND" property="systemtype">
<![CDATA[a.systemtype = #systemtype#]]>
</isNotEmpty>
</dynamic>
order by a.seq
</select>
public JsonView treeGrid(){
Map param=new HashMap();
QueryParam qp=QueryParam.getInstance2("sys.queryResourceInfo", param ,-1, -1);
List<OrgVO> list=this.getBasBS().query(qp);
return new JsonView(list);
}
treeGrid = $('#treeGrid').treegrid({
url : '${ctx}/sys/resource/treeGrid',
idField : 'id',
treeField : 'name',
parentField : 'pid',
initialState:"collapsed",
fit : true,
fitColumns : false,
border : false,
frozenColumns : [ [
{
field : 'id',
title : '编号',
width : 80
},{
field : 'name',
title : '资源名称',
width : 200
} , {
field : 'url',
title : '资源路径',
width : 150
}
] ],
columns : [ [{
width : '150',
title : '上级资源',
field : 'pid'
}, {
field : 'seq',
title : '排序',
width : 60
},{
field : 'icon',
title : '图标',
width : 150
} ,{
field : 'state',
title : '状态',
width : 60,
},{
field : 'resourcetype',
title : '资源类型',
width : 100,
formatter : function(value, row, index) {
switch (value) {
case 1:
return '按钮';
case 0:
return '菜单';
}
}
} ,{
field : 'systemtype',
title : '子系统',
width : 100,
formatter : function(value, row, index) {
switch (value) {
case 0:
return '工程公共资源';
case 1:
return '总包工程资源';
case 2:
return '分包工程资源';
case 3:
return '查询统计资源';
case 4:
return '系统管理资源';
}
}
} ] ],
toolbar : '#toolbar'
});
$(document).ready(function(){
makeTree("subject");
});
function makeTree(id){
$('#' + id).tree({
animate: true,
url: '/服务端地址/',
});
}
<ul id="subject"></ul>
进入页面就执行makeTree()方法,这时请求远程时没有携带“id”参数过去,那么pid就为null,这样就取出了顶级树,当用户点击节点时,组件会自动发送ajax,并带上id过去,这时在服务端将接收的id值赋给pid,取出子树,以此递归。public JsonView treeGrid(){
Map param=new HashMap();
QueryParam qp=QueryParam.getInstance2("sys.queryResourceInfo", param ,-1, -1);
List<OrgVO> list=this.getBasBS().query(qp);
return new JsonView(list);
}
[/quote]
哈哈你就从了吧。
默认不加条件,所有最外面的父节点查询出来。
然后点击 onBeforeExpand 的时候当前的id 传进去查询子节点。public JsonView treeGrid(){
Map param=new HashMap();
QueryParam qp=QueryParam.getInstance2("sys.queryResourceInfo", param ,-1, -1);
List<OrgVO> list=this.getBasBS().query(qp);
return new JsonView(list);
}
public JsonView treeGrid(String pid){
Map param=new HashMap();
QueryParam qp=QueryParam.getInstance2("sys.queryResourceInfo", param ,-1, -1);
List<OrgVO> list=this.getBasBS().query(qp,pid);//这里作条件查询,pid为空就查父类,不空就查子类
return new JsonView(list);
}
$(function() {
$('#treeGrid').treegrid(
{
url : contextpath + '/cityTree/cityTree.do',
idField : 'id',
treeField : 'text',
resizable : true,
collapsible : true,
height : $(document.body).height() - 2,
width : 200 - 2,
columns : [ [ {
field : 'id',
hidden : true,
sortable : false
}, {
field : 'text',
width : 190,
sortable : false
} ] ],
onClickCell : function(field,row) {
parent = row;
if(0<row.id){
$("#datagrid_list").datagrid('reload', {
cityid : row.id,
isdel : 0
});}
},
onExpand : function(row){//默认第一次展开会去访问后台,如果想每次展开都去请求加上onExpand事件
$("#datagrid_list").datagrid('reload', {
cityid : row.id,
isdel : 0
});
}
});
})