关于jquery的easyUI树形控件问题

<inputid="buildfloor" value="1"/> //这是绑定的树形控件

$('#buildfloor').combotree({ //这是javascript从数据库取数据
url: sy.contextPath +'/master/build!bindCombox.eh',
valueField:'id',
textField:'text',
required: true
});

synchronizedpublic void bindCombox() //这是java action中的方法已取到数据,
{
//Json json=new Json();
HqlFilter hqlFilter=newHqlFilter(getRequest());
hqlFilter.addFilter("QUERY_t#deleteFlag_I_EQ","0");
hqlFilter.addFilter("QUERY_t#type_S_EQ","buildFloor");
List<Dictionary>dictionaryList=dictionaryServiceI.findByFilter(hqlFilter);
ArrayList<String>id=new ArrayList<String>();
for(inti=0;i<dictionaryList.size();i++)
{
id.add(dictionaryList.get(i).getValue());
}
//String[] buildfloor=build.getBuildNo().split(",");
writeJson(id);
}
我想把Dictionary中的两个属性放到jquery easyui中的树形下拉选框中,请问怎么实现啊。

这个是我现在的效果,但我想实现下面的效果,求大神给个例子啊。或者帮我改下。

ComboTree的数据结构和Tree一样

每个node节点都有这些属性,你想把QUERY_t#deleteFlag_I_EQ和QUERY_t#type_S_EQ两个属性放进去,可以放到attributes中形如:

attributes:[{

    QUERY_t#deleteFlag_I_EQ:“具体值”,

    QUERY_t#type_S_EQ:"具体值"

}]

当然这种形式的数据要你自己转换成json类型的。

不能解决可以提问,互相探讨,希望可以帮到你!

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-05-19
easyui-tree 数据是要把子节点的数据放到父节点的children参数里面
public class TreeNode 这是我自己定义的一个java类,里面的属性写在下面

private String id;
private String text;//菜单名字
private String iconCls;//菜单图标样式名
private String state;//状态
private boolean checked;
private List<TreeNode> children;//子节点list
private Map<String, Object> attributes;//节点数据

public TreeNode(String id, String text, //TreeNode的构造方法
Map<String, Object> attributes) {
super();
this.id = id;
this.text = text;
this.children = new ArrayList<TreeNode>();
this.attributes = attributes;
}

action里面

List<TreeNode> nodes = new ArrayList<TreeNode>();创建一个可以放TreeNode的list
Map<String,TreeNode> map=new LinkedHashMap<String, TreeNode>();//存放节点用

HqlFilter hqlFilter=newHqlFilter(getRequest());
hqlFilter.addFilter("QUERY_t#deleteFlag_I_EQ","0");
hqlFilter.addFilter("QUERY_t#type_S_EQ","buildFloor");
List<Dictionary>dictionaryList=dictionaryServiceI.findByFilter(hqlFilter);
你需要知道你的Dictionary 上下级关系的id
for(int i=0;i<dictionaryList.size();i++) {
Dictionary t = dictionaryList.get(i);
Map<String,Object> beanMap=MapUtil.beanToMap(t );//把一个实体类转换成一个map 方法在下面
节点id,树显示时的名称
TreeNode treeNode = new TreeNode(id, name, beanMap);
if(t是父节点){
map.put(id,treeNode);

nodes .add(treeNode);
} else{
TreeNode treeNode1 = map.get(t的父id);

treeNode1 .appendChild(treeNode1 );
}

}
writeJson(nodes );
最后返回nodes
大概的过程就是这样,希望对你有帮助 atrributes里面就是存放了Dictionary里面的所有属性

public class MapUtil

/**
* 将一个 JavaBean 对象转化为一个 Map
* @param bean 要转化的JavaBean 对象
* @return returnMap 转化出来的 Map 对象
*/
public static <T> Map<String, Object> beanToMap(T bean) {

Class<? extends Object> type = bean.getClass();
Map<String, Object> returnMap = new HashMap<String, Object>();

try {
BeanInfo beanInfo = Introspector.getBeanInfo(type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor descriptor : propertyDescriptors) {
String propertyName = descriptor.getName();
if (!propertyName.equals("class")) {
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(bean, new Object[0]);
returnMap.put(propertyName, result != null ? result : "");
}
}
} catch (IntrospectionException e) {
throw new RuntimeException("分析类属性失败", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("分析类属性失败", e);
} catch (InvocationTargetException e) {
throw new RuntimeException("分析类属性失败", e);
}
return returnMap;
}本回答被提问者采纳
相似回答