easyui 的tree数据 从nutz后台动态加载,返回数据的格式
15 回复
[{
"id": 1,
"text": "Node 1",
"state": "closed",
"children": [{
"id": 11,
"text": "Node 11"
},{
"id": 12,
"text": "Node 12"
}]
},{
"id": 2,
"text": "Node 2",
"state": "closed"
}]
@了没有提醒 nutzwk1.0版本可以参考的,这是自己改的
@At("/mytree")
@Ok("json")
@RequiresAuthentication
public Object myMenu(HttpServletRequest req) {
String userId = StringUtil.getUid();
List<Sys_menu> list = userService.fetchTopMenus(Integer.parseInt(userId));
List<Tree> tree = new ArrayList<Tree>();
for (Sys_menu menu : list) {
Tree obj = Tree.Me();
obj.setId(menu.getId()+"");
obj.setTitle(menu.getName());
obj.setIcon(menu.getIcon());
Map<String, Object> attr = new HashMap<>();
attr.put("href", menu.getHref());
attr.put("depth", 0);
obj.setAttributes(attr);
obj.setChildren(fetchSubMenus(menu));
tree.add(obj);
}
log.info(Json.toJson(tree));
return tree;
}
添加回复
请先登陆