我用uibinder建一棵树,想要得到这个:
-tree1
treeel1
treeel2
+tree2
-tree3
element
我在xml上定义的内容:
...
<g:Tree ui:field='tree'>
<g:TreeItem ui:field='treeEl'>
<g:Tree ui:field='tree1'>
<g:TreeItem ui:field='subTreeEl'>
</g:TreeItem>
</g:Tree>
</g:TreeItem>
</g:Tree>
....
在客户端上我有这个:
void treework() {
AsyncCallback<Map<Data,List<Value>>> callback=new AsyncCallback<Map<Data,List<Value>>>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(Map<Data, List<Value>> result) {
for (Entry<Data, List<Value>> it : result
.entrySet()) {
treeEl= new TreeItem();
String key = String.valueOf(it.getKey().getName());
List<Value> list = it.getValue();
treeEl.setText(key);
for (Value v: list) {
subTreeEl = new TreeItem();
subTreeEl.setText(v.getName());
tree1.addItem(subTreeEl);
}
subTreeEl.setState(true, true);
treeEl.setState(true, true);
treeEl.addItem(tree1);
tree.addItem(treeEl);
}
}
};
rpcService.getData(callback);
}
我得到的所有这些都是带有项目的树,但是所有的inneritems都在最后一个树值中,如下所示:
+tree1
+tree2
-tree3
treeel1
treeel2
element
我做错了什么,有什么建议吗?我想为每个treeitem名称获取一个树元素,并将元素列表的映射添加到数据名称
答案 0 :(得分:1)
由于要添加的数据是动态的,因此请将xml文件修改为:
<g:Tree ui:field='tree'>
</g:Tree>
用于向树添加数据的客户端代码如下:
for (Entry<Data, List<Value>> it : result.entrySet()) {
TreeItem treeEl= new TreeItem();
String key = String.valueOf(it.getKey().getName());
List<Value> list = it.getValue();
treeEl.setText(key);
for (Value v: list) {
TreeItem subTreeEl = new TreeItem();
subTreeEl.setText(v.getName());
treeEl.addItem(subTreeEl);
}
treeEl.setState(true, true);
tree.addItem(treeEl);
}