Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Recursive mustache

$
0
0
I would like to display a tree structure using recursive mustache template,  http://jsfiddle.net/BigZolo/HPge3/3/

It seems falling to infinite loop. Does this concept wrong at all?

  1. var data = [{
  2.     title: 'title1',
  3.     hasChild: true,
  4.     children: [{
  5.         title: 'sub1',
  6.         hasChild: false
  7.     },
  8.                {
  9.                    title: 'sub2',
  10.                    hasChild: true,
  11.                    children: [{
  12.                        title: 'sub21',
  13.                        hasChild: false
  14.                    }]
  15.                }
  16.     ]
  17. },{
  18.     title: 'title2',
  19.     hasChild: false
  20. }];

  21. var template = can.view('#main', {data: data});
  22. $('#puthere').append(template);
  23. <script id='main' type='text/mustache'>
  24. <ul>
  25. {{#data}}
  26.     <li>{{title}}
  27.     {{#children}}
  28.     <ul>
  29.         {{>recursive}}
  30.     </ul>
  31.     {{/children}}
  32.     </li>
  33. {{/data}}
  34.  </ul>    
  35. </script>
  36. <div id='puthere'></div>
  37. <script id='recursive' type='text/mustache'>
  38.     <li>{{title}}
  39.     {{#children}}
  40.     <ul>
  41.         {{>recursive}}
  42.     </ul>
  43.     {{/children}}
  44.  </li>
  45. </script>

Viewing all articles
Browse latest Browse all 3491

Trending Articles