首页 > 代码库 > JS中模板嵌套学习(代码)

JS中模板嵌套学习(代码)

<script src="http://www.mamicode.com/script/jquery-1.4.2.js"></script>
    <script src="http://www.mamicode.com/script/jsrender.js"></script>
    <script id="header" type="text/x-jsrender">
        <tr>
               <th>序号</th>
               <th>标题</th>
               <th>图片</th>
               <th>点击次数</th>
               <th>支持</th>
               <th>反对</th>
               <th>时间</th>
               <th>操作</th>
           </tr>
    </script>
    <script id="templ" type="text/x-jsrender">
        {{include tmpl="#header" /}}
        {{for #data.photos}}
        <tr>
        <td>{{:#index+1}}</td>
        <td>{{:PTitle}}</td>
        <td>{{:PUrl}}</td>
        <td>{{:PClicks}}</td>
        <td>{{:PUp}}</td>
        <td>{{:PDown}}</td>
        <td>{{:PTime}}</td>
        <td>修改 删除</td>
        </tr>
        {{/for}}
    </script>

 

 {{include tmpl="#header" /}}中的include前不要加#,否则就是坑

模板嵌套demo网址:http://borismoore.github.io/jsrender/demos/demos.html