jsp:
// -------------------------ajax异步刷新--------------------
//一级子节点
$(function ()
{
$("#tree1").ligerTree(
{
url : 'node!getNodeTree.action?' + $.param( {
parentid : '-1',
iconroot : '../'
}),
checkbox:false,
nodeWidth : 120,
onBeforeExpand: onBeforeExpand,
attribute : [ 'nodename', 'url' ],[d1]
onClick : function(node) {
nodeID = node.data.nodeid;
$("#ptid").val(nodeID);
[d2] [d3] rootID=node.data.rootid;
$("#rootid").val(rootID);
if (nodeID != 0) {
gridManager.setOptions( {
parms : [ {
name : 'filter_EQL_nodeid[d4] ',
value : node.data.nodeid
} ]
});
} else {
gridManager.setOptions( {
});
}
gridManager.loadData(true);
}
});
manager = $("#tree1").ligerGetTreeManager();
});
//二级子节点
function onBeforeExpand([d5] node)
{
if (node.data.children && node.data.children.length == 0) {
manager.loadData(node.target,
'node!getNodeTree.action?' + $.param( {
parentid : node.data.nodeid
}));
}
}
------------------------------------------------------------------------
action:
//按parentId查询栏目
public String getNodeTree() {
try {
HttpServletRequest request = Struts2Utils.getRequest();
String root = request.getParameter("root");
if (root != null)
root = new String(root.getBytes("iso8859-1"), "UTF-8");//处理乱码问题
//获得用户id
OperatorDetails userDetails = SpringSecurityUtils.getCurrentUser();[d7]
Integer currUserId = userDetails.getSysuser().getUserid();
List<Node> list = NodeService.getTree(request.getParameter("parentid"),currUserId);
if(list!=null && list.size()>0){
JSONObject jo = new JSONObject();
String treeJSON = "";
for (Node entity : list) {
jo.put("text", entity.getNodename());
jo.put("nodeid", entity.getNodeid());
jo.put("pid", entity.getParentid());
jo.put("isexpand", "false");
jo.put("rootid", entity.getRootid());
//判断是否有子节点
if(entity.getChildcnt()>0){
jo.put("isleaf", false);
}else{
jo.put("isleaf", true);
}
[d8] jo.put("children", "[]");
treeJSON += jo.toString() + ",";
}
if (!treeJSON.equals(""))
treeJSON = treeJSON.substring(0, treeJSON.lastIndexOf(","));
if (root != null && !root.equals("")) {
treeJSON = "[{"text":"" + root
+ "","nodeid":"0","pid":"-1","children":["
+ treeJSON + "]";
treeJSON += "}]";
} else {
treeJSON = "[" + treeJSON + "]";
}
// 解决叶子节点问题,临时办法。API中有isleaf函数,没查到用法!!!
if (treeJSON.equals("[{}]"))
treeJSON = "[]";
Struts2Utils.renderText(treeJSON);
return NONE;
}
} catch (Exception ex) {
logger.error(ex.getMessage());
}
Struts2Utils.renderText("[]");
return NONE;
}
------------------------------------------------------------------------
service:
/**
* 根据条件查询tree
* @param parentid
* @return
*/
public List<Node> getTree(String parentid)
{
//管理员直接查询全部 不限制
Query query = nodeDao.getSession().createSQLQuery(HQL);
query.setParameter("nodeid", Long.parseLong(parentid));
List<Node> result = new ArrayList<Node>();
List tmpList = query.list();
for (Object tmp : tmpList) {
Object[] obj = (Object[])tmp;
Node node = new Node();
node.setNodename(obj[0].toString());
node.setNodeid(StringValueUtils.getLong(obj[1].toString()));
node.setParentid(StringValueUtils.getLong(obj[2].toString()));
node.setChildcnt(StringValueUtils.getInt(obj[4].toString()));
node.setRootid(StringValueUtils.getLong(obj[3].toString()));
result.add(node);
}
return result;
}
------------------------------------------------------------------------
dao:
@Component
public class NodeDao extends HibernateDao<Node, Long> {
}
------------------------------------------------------------------------