2012-10-16 4 views
2

{{each}} 문장을 통해 반복되는 템플릿 집합이 있습니다. jquery tmpl within each

<script id="inTmpl" type="text/x-jquery-tmpl"> 
     ${sub.title} 
    </script> 
    <script id="outTmpl" type="text/x-jquery-tmpl"> 
     <div> 
     {{each(i, sub) parent}} 
       ${sub.title} 
       {{tmpl "#inTmpl"}} 
     {{/each}} 
     </div> 
    </script> 
    <script type="text/javascript"> 
      $(function() { 
       $("#outTmpl").tmpl({ 
        "parent": [ 
         {"title": "a"}, 
         {"title": "b"} 
        ] 
       }).appendTo("body"); 
      }); 
    </script> 

그럼 내가 오류 같은 코드는 다음과 같습니다 "catch되지 않은 ReferenceError가 : 서브가 정의되어 있지 않습니다." 왜?!

답변

0

내가 믿는 하위 개체에 새 템플릿을 전달해야합니다. 나는이 정보를 어디서 얻었

{{tmpl(sub) "#inTmpl"}} 

여기처럼

그래서 두 번째 템플릿을 렌더링하는 선이 보일 것입니다. 나는 아직 그것을 시도하지 않았다. 당신은 여기에 보관 된 문서를 찾을 수 있습니다

http://skilldrick.co.uk/tmpl/#slide14

0

:

<script id="inTmpl" type="text/x-jquery-tmpl"> 
    ${title} 
</script> 

<script id="outTmpl" type="text/x-jquery-tmpl"> 
    <div> 
    {{each(i, sub) parent}} 
     ${sub.title} 
     {{tmpl(sub) "#inTmpl"}} 
    {{/each}} 
    </div> 
</script> 

<script type="text/javascript"> 
$(function() { 
    $("#outTmpl").tmpl({ 
    "parent": [ 
     {"title": "a"}, 
     {"title": "b"} 
    ] 
    }).appendTo("body"); 
}); 
</script> 
: 여기 http://web.archive.org/web/20120921050105/http://api.jquery.com/template-tag-tmpl/

는 작업 버전입니다