12
我正在使用jquery模板来生成树结构来显示部分和项目的树视图。JQuery模板 - 太多递归
数据的结构是这样的,其中每个部分都有项目和节和每个项目可以有多个部分:
section
items
item
sections
item
sections
sections
section
sections
items
...and so on
我的模板然后递归调用对方:
<script id="my-item-tmpl" type="text/x-jquery-tmpl">
<li>
<span>${text}</span>
<ul>
{{each sections}}
{{tmpl($value) "sectionTmpl"}}
{{/each}}
</ul>
</li>
</script>
<script id="my-section-tmpl" type="text/x-jquery-tmpl">
<li>
<span>${text}</span>
<ul>
{{each items}}
{{tmpl($value) "itemTmpl"}}
{{/each}}
{{each sections}}
{{tmpl($value) "sectionTmpl"}}
{{/each}}
</ul>
</li>
</script>
$("#my-item-tmpl").template('itemTmpl');
$("#my-section-tmpl").template('sectionTmpl');
$.tmpl('sectionTmpl', { section }).appendTo(this);
我我发现然而,大约4级进入结构我收到"too much recursion
“我的控制台中的错误。
这是只是jQuery模板的限制te引擎?
编辑:
我已经通过去除{{each}}
并用{{tmpl}}
调用替换它解决了这一点。 {{each}}
不需要。我还将每个{{tmpl}}
呼叫打包在{{if}}
以确保收集存在。
也许这是一个警告,你即将得到一个堆栈溢出错误。 – 2011-05-12 19:36:29