Recursive calls of custom elements (trees)

36 views
Skip to first unread message

Dave Ford

unread,
Mar 19, 2015, 11:25:53 AM3/19/15
to polym...@googlegroups.com

I saw an example in the docs using the ref attribute of template. I want to do the same thing using custom elements.

I know this syntax won't work but it should convey the general idea of what I am trying to do:

<{{node.nodeType }} node={{node}}>

In my old GWT app I had a strategy function for this purpose:

NodeRenderer r = determineNodeRenderer(node.nodeType )
r.render(node)

How would I achieve similar using polymer?

Thanks

df...@smart-soft.com

unread,
Mar 23, 2015, 2:08:16 PM3/23/15
to polym...@googlegroups.com, df...@smart-soft.com
Here is one solution to the problem using "if":

<template bind="{{node}}">
<template if="{{type == 'fm'}}">
<fm-view node="{{}}"></fm-view>
</template>
<template if="{{type == 'tab'}}">
<tab-view node="{{}}"></tab-view>
</template>
<template if="{{type == 'xor'}}">
<xor-view node="{{}}"></xor-view>
</template>
<template if="{{type == 'var'}}">
<var-view node="{{}}"></var-view>
</template>
</template>

And here is another using "template ref":

<template bind="{{node}}">
<template id="fm"><fm-view node="{{}}"></fm-view></template>
<template id="tab"><tab-view node="{{}}"></tab-view></template>
<template id="xor"><xor-view node="{{}}"></xor-view></template>
<template id="var"><var-view node="{{}}"></var-view></template>

<template bind ref="{{type}}"></template>

</template>

Neither seems all that elegant however. Any other suggestions?
Reply all
Reply to author
Forward
0 new messages