我正在尝试使用jsRender实现一种递归模板的方法。问题是,我的数据对象有一个一元自引用层次结构,它需要递归循环来显示所有属性。这里的例子是一个论坛帖子,它可以包含任意数量的回复帖子。每个回复帖子可以包含任意数量的子帖子,依此类推。除了递归部分,我还有下面的代码在运行。我只能通过Googles找到一个对此的远程引用,所以到目前为止我得到的是:
<script id="forumPostsTemplate" type="text/x-jsrender">
<article class="forumPost">
<header class="forumPostHeader">{{:PostSubject}}
<div class="info">By: Some Person, {{:CreatedDate}} <a href="">Flag as innapropriate</a> </div>
</header>
<div class="content">
{{:PostContent}}
{{for Replies}}
{{:Replies tmpl="#forumPostsTemplate"}}
{{/for}}
</div>
</article>
</script>有没有人有过使用这种功能的经验?我目前正在运行最新版本的jsRender,如果有帮助的话。
发布于 2012-05-08 06:58:52
根据这个jsRender的例子,像这样调用你的模板行吗?
https://github.com/BorisMoore/jsrender/blob/master/demos/step-by-step/06_template-composition.html
{{for Replies tmpl="#forumPostsTemplate"/}}发布于 2012-05-08 12:39:17
树标记控件的这三个不同版本正好说明了这种递归:
http://www.jsviews.com/#samples/tag-controls/tree
https://stackoverflow.com/questions/10488499
复制相似问题