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);
I을 그러나 약 4 레벨의 구조를 찾으면 내 콘솔에 "too much recursion
"오류가 나타납니다.
이것은 단지 jQuery Templa의 제한 사항입니까? 테 엔진?
편집 :
나는 {{each}}
을 제거하고 {{tmpl}}
전화로 교체하여이 문제를 해결했습니다. {{each}}
은 필요하지 않았습니다. 나는 또한 각각의 {{tmpl}}
전화를 {{if}}
에 포장하여 콜렉션이 존재하는지 확인했습니다.
아마도 스택 오버플로 오류가 발생한다는 경고입니다. –