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?
- var data = [{
- title: 'title1',
- hasChild: true,
- children: [{
- title: 'sub1',
- hasChild: false
- },
- {
- title: 'sub2',
- hasChild: true,
- children: [{
- title: 'sub21',
- hasChild: false
- }]
- }
- ]
- },{
- title: 'title2',
- hasChild: false
- }];
- var template = can.view('#main', {data: data});
- $('#puthere').append(template);
- <script id='main' type='text/mustache'>
- <ul>
- {{#data}}
- <li>{{title}}
- {{#children}}
- <ul>
- {{>recursive}}
- </ul>
- {{/children}}
- </li>
- {{/data}}
- </ul>
- </script>
- <div id='puthere'></div>
- <script id='recursive' type='text/mustache'>
- <li>{{title}}
- {{#children}}
- <ul>
- {{>recursive}}
- </ul>
- {{/children}}
- </li>
- </script>