# Problem with TreeModel and <template> when removing nodes

tisaksen
44 5

Hello

I have the a tree which I am displaying with the following zul:

<tree id="salesorderTree" rows="0" width="100%" model="@bind(vm.salesorderTreeModel) @template(not empty each.children ? 'product' : 'detail')">
<treecols sizable="true">
<treecol hflex="24" label="Varelinjer"/>
</treecols>
<template name="product" var="productNode" status="spn">
<treeitem>
<treerow>
</treerow>
</treeitem>
</template>
<template name="detail" var="detailNode" status="sdn">
<treeitem>
<treerow>
</treerow>
</treeitem>
</template>


</tree>

This will output a simple tree with this layout:

root
product 1
product detail
product detail
product 2
product detail


and so forth.

This is fine but the problem is when I remove all product details on a product I get an error:

This means it's actually trying to render the "detail" template when the detail is in fact not there anymore.

Anyone know how to solve this? Or maybe can see what I'm doing wrong?

delete retag edit

1

in you code not empty each.children ? 'product' : 'detail', so if you remove all the children of product then goes to 'detail', doesn't it?you have to has a way to determine the node is a product or not, shouldn't depend on children.

( 2013-03-12 11:10:31 +0800 )edit

Oh right, I see the problem. Maybe I can just use isLeaf (since these are TreeNode's anyway) so it will be @template(each.leaf ? 'detail' : 'product')

( 2013-03-12 12:22:10 +0800 )edit
Be the first one to answer this question!
[hide preview]