日期:2014-05-16  浏览次数:20365 次

EXT js -------Tree之1:n


业务层方法

public String query() {

List<Role> list = roledao.query();

List<Map<String,Object>> rolelist = new ArrayList<Map<String,Object>>();

for (Role role : list) {

Map<String,Object> roles= new HashMap<String, Object>();

roles.put("id", String.valueOf(role.getRid()));

roles.put("text", role.getName());

roles.put("cls", "folder");

List<Map<String,Object>> userlist =new ArrayList<Map<String,Object>>();

for (Users users : role.getUsers()) {

Map<String,Object> user=new HashMap<String, Object>();

user.put("id", String.valueOf(users.getId()));

user.put("text",users.getUsername());

user.put("leaf", true);

//包含checked属性时, 生成的树中带有复选框

user.put("checked", false);

userlist.add(user);

}

roles.put("children", userlist);

rolelist.add(roles);

}

// Map<String,List<Map<String,Object>>> map= new HashMap<String, List<Map<String,Object>>>();

// map.put('root',rolelist );

return JSONArray.fromObject(rolelist).toString();

}


控制层方法

public class RoleAction implements Action {

private IRoleService rsi;

private String json;//注入json