-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Example zul:
<tree model="@load(vm.definitions)" selectedItem="@bind(vm.selected)" checkmark="true"> <treecols visible="false"> <treecol label="" /> </treecols> <treechildren> <template name="model" var="definition"> <treeitem> <treerow> <treecell label="@load(definition.name)" /> </treerow> </treeitem> </template> </treechildren> </tree>
items in View Model:
private TreeModelDefinition definitions;
and TreeModelDefinition:
public class TreeModelDefinition extends AbstractTreeModel<Definition> { public boolean isLeaf(Definition e) { ... } public Definition getChild(Definition e, int i) { .... } public int getChildCount(Definition e) { ... } }
Here is a complete tree mvvm on-demand answer on stackoverflow:
The fully working sample code is on github.com at https://github.com/simbo1905/zktreemvvm
I begun preparing the test with Hello World, but compiler generated errors: http://zkfiddle.org/sample/t8u454/1-Hello-World-MVVM-2
test Tree here: http://zkfiddle.org/sample/1pkf6ee/1-test-Tree-MVVM
In this test shown another problem: Title of window must update on "test Title".
Hello:
Same for me. Any solutions?
multiple don't work:
http://zkfiddle.org/sample/1pkf6ee/3-test-Tree-MVVM
when using tree with model, you have to set multiple on the model.(see TreeSelectableModel interface)
ex,
definitions = new TreeModelDefinition( root );
definitions.setMultiple(true);
and for the selection on multiple, you need to bind to selectedItems
for the displaying like a pointer, it looks like a kind of weird bug when using tree+model and treechildren.
basically, you shouldn't add tree-children in the code, (here is a tree template example with normal EL , http://books.zkoss.org/wiki/ZK_Developer's_Reference/MVC/View/Template/Tree_Template)
and for your case, try this
<tree model="@load(vm.definitions)" selectedItem="@bind(vm.selected)" checkmark="true"> <treecols visible="false"> <treecol label="" ></treecol> </treecols> <template name="model" var="definition"> <treeitem> <treerow> <treecell label="@load(definition.name)" ></treecell> </treerow> </treeitem> </template> </tree>
got it,this is not bug, for the tree's template, it has to be in tree directly, if you put it in children, then render cannot find it, and a default one will be applied.
Asked: 2012-05-28 05:02:14 +0800
Seen: 730 times
Last updated: Dec 26 '12