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