Nesting a template with itself depending on data subset ...

22 views
Skip to first unread message

imbibinebe

unread,
Mar 9, 2012, 2:07:55 PM3/9/12
to JavaScript Templates Engine PURE
Hi,
I trying to build a table template which is meant to display any JSON
object we give it, with dynamic sorting and filtering features. A
shark template which eats anything that looks like JSON :D
While rendering the template, depending on properties (type, ie ...)
of a subset of the JSON object, i would like to append a new row&cell
which will contain the same template (table) with a different #id than
its parent template. This nested template will be rendered later with
the JSON object subset if the user wants to (by clicking on an cell
expand button for example).
If you know how Firebug displays JSON objects, my shark template will
do the same + sorting&filtering features ;)

What I do til now is:
While rendering the base template, i save JSON object subsets in event
handlers of user interaction tags like 'onclick="dataSubset={JSON
subset};functionThatReRenderBaseTemplate();"'
Then, the base template is re-rendered with the data subset. This
works perfectly !

Now I'd like to keep what was rendered before instead of replacing
everything.

Does anyone have a solution ? I hope you understood what I want, my
english is not so good and it might be a bit tricky ...

Mic (BeeBole)

unread,
Mar 10, 2012, 4:07:22 PM3/10/12
to JavaScript Templates Engine PURE
I tried to extend the example from the docs:
http://beebole.com/pure/documentation/recursion-example/
It is with UL/LI: https://gist.github.com/2013198

You need to compile the template.
If there are children properties render them too with the same
compiled template(rfn in the example), but hide them.
Then finally, onclick just show the child if present, without all the
JSON in the HTML.

imbibinebe

unread,
Mar 16, 2012, 11:12:40 AM3/16/12
to JavaScript Templates Engine PURE
Compiled templates are very useful and fast. Eventually I choose to re-
render the base template each time data subset has to be displayed
because nested tables can become very hugly :) But I still use
compiled templates to do that.
Thanks for your help Mic !
Reply all
Reply to author
Forward
0 new messages