【发布时间】:2016-04-05 13:12:30
【问题描述】:
经过数小时的搜索,我找不到我的问题的正确答案。我想用车把显示任意树深度。把手中的递归模板有一个很好的小提琴示例(https://jsfiddle.net/adamboduch/5yt6M/),但我无法获得树的深度。 @index 只告诉我每个元素的位置。
我的部分模板:
<script id="teamspeak_channel_recursive" type="text/x-handlebars-template">
{{#each childChannel}}
<tr class="viewer-table-row">
<td class="viewer-table-cell">
<span></span>
<span class="viewer-label">{{name}}</span>
<span></span>
</td>
</tr>
{{#if childChannel}}
{{> teamspeak_channel_recursive}}
{{/if}}
{{/each}}
</script>
我想通过 css margin left 或 css class 根据 deph 来命名。我也尝试过使用参数,但根本不允许计算数字或进行任何数学运算。数学助手也没有帮助。据我所知,模板中的 Javascript 是被禁止的。
<script id="teamspeak_channel_recursive" type="text/x-handlebars-template">
{{#each childChannel}}
<tr class="viewer-table-row">
<td class="viewer-table-cell">
<span></span>
<span class="viewer-label">{{name}}</span>
<span></span>
</td>
</tr>
{{#if childChannel}}
{{> teamspeak_channel_recursive deph=({{../deph}}+1) }} <- dosen't work only statc values or the context itself is working
{{/if}}
{{/each}}
</script>
简而言之,我被卡住了,除了使用有序列表并将显示模式设置为 tablecell 之外,我没有找到出路。但这不是我想要的。同样迭代上下文以在之前添加递归级别也不是一个好的选择。
模型(不完整):
type": "channel",
"childChannel":
[
{
"type": "channel",
"childChannel":
[
{
"type": "channel",
"childChannel": null,
"childClient": null,
"name": "AFK Area"
}
],
"childClient": null,
"name": "WoW / SWToR / GuildWars2 hype"
},
{
"type": "channel",
"childChannel":
[
{
"type": "channel",
"childChannel": null,
"childClient": null,
"name": "Rumidler (AFK)"
}
],
"childClient": null,
"name": "FPS CS:GO Hype"
}
],
"childClient": null,
"name": "Hall of Games"
【问题讨论】:
标签: javascript html templates recursion handlebars.js