Вы можете определить свой TaskList
как частичный и включить его рекурсивно как документация подсказки.
Шаблоны:
<script type="text/template" id="projects">
{{#Projects}}
<div>
Project: <b>{{ProjectName}}</b>
</div>
{{>taskList}}
{{/Projects}}
</script>
<script type="text/template" id="task-list">
{{#TaskList}}
<ul>
<li>
{{TaskListName}} <em>{{CreatedBy}}</em>
{{>taskList}}
</li>
</ul>
{{/TaskList}}
</script>
JavaScript:
var data = {
Projects: [
{
ProjectName: "Project 1",
TaskList: [{
TaskListName: "Name 1",
CreatedBy: "Person 1"},
{
TaskListName: "Name 2",
CreatedBy: "Person 2",
TaskList: [{
TaskListName: "Sub Name",
CreatedBy: "Same Person"},
{
TaskListName: "Sub Name 2",
CreatedBy: "Person 1"},
{
TaskListName: "Sub Name 3",
CreatedBy: "Person 3-2",
TaskList: [{
TaskListName: "Sub Sub Name",
CreatedBy: "Person 3-3"}]}]}]},
{
ProjectName: "Project 2",
TaskList: [{
TaskListName: "Name 3",
CreatedBy: "Person 3"},
{
TaskListName: "Name 4",
CreatedBy: "Person 4"}]}]
},
template = $('#projects').html(),
partials = {
taskList: $('#task-list').html()
},
html = Mustache.render(template, data, partials);
document.write(html);
Вот jsFiddle, чтобы увидеть его в действии- http://jsfiddle.net/maxbeatty/ND7xv/