gpt4 book ai didi

handlebars.js - Handlebars : recursive tree structure

转载 作者:行者123 更新时间:2023-12-04 17:22:26 25 4
gpt4 key购买 nike

我有一个任意深度的树结构,我想用 Handlebars 显示它。我没有看到任何递归的方法。如果我知道深度,我想我可以对其进行硬编码,但它可以是任意深度。

像这样的东西,但它需要在显示子部分递归。

{{#aNode}}
{{id}
{{name}}
{{description}}
...spew this same template with each member of {{#children}}...
{{/aNode}}

Handlebars 有迭代集合的方法,但我看不到递归到子项中的方法

最佳答案

这是一篇不错的文章和 jsfiddle 准确描述了如何做到这一点(这或多或少是 Chris Kessel 在他的回答中所描述的):

http://www.boduch.ca/2014/03/recursive-list-building-with-handlebars.html

关于handlebars.js - Handlebars : recursive tree structure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19170224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com