JTemplate 학습 (1)

템 플 릿 바 인 딩 데 이 터 를 사용 하여 순환 을 삽입 할 수 있 습 니 다.
참고:http://www.doc88.com/p-6621237324128.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- saved from url=(0043)http://jtemplates.tpython.com/example1.html -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="Scripts/jTemplates/example/jquery.js"></script>
    <script type="text/javascript" src="Scripts/jTemplates/jquery-jtemplates.js"></script>
    <title>jTemplates</title>
    <script type="text/javascript">

        $(document).ready(function () {
            //     JsonData,        ,      
            var data = {
                name: 'User list',
                list_id: 4,
                table: [
                { id: 1, name: 'Anne', age: 22, mail: '[email protected]', childs: [{ name: "k1", age: "5" }, { name: "k2", age: "3" }, { name: "k2", age: "3" }, { name: "k2", age: "3" }] },
                { id: 2, name: 'Amelie', age: 24, mail: '[email protected]' },
                { id: 3, name: 'Polly', age: 18, mail: '[email protected]' },
                { id: 4, name: 'Alice', age: 26, mail: '[email protected]' },
                { id: 5, name: 'Martha', age: 25, mail: '[email protected]' }
                ]
            };

            //     ,  id:template
            $("#result1").setTemplateElement("template");

            //     ,    
            $("#result1").processTemplate(data);

            //setTemplateElement           
            //processTemplate              
            //$T            
            //$P              
            //$Q.version     JTemplate     

            //{#if $T.list_id == 3}System List{#elseif $T.list_id == 4}User List{#else}Error List{#/if} //if else   

            //{#foreach $T.table as record}{$T.record.name}{#/for} //  
            //{#foreach $T.table as record begin=1}{$T.record.name}{#/for} //      
            //{#foreach $T.table as record count=2}{$T.record.name}{#/for} //      
            //{#foreach $T.table as record step=2}{$T.record.name}{#/for} //    

            //{$T.record$index}   , 0  
            //{ $T.record$iteration }   , 0  
            //{ $T.record$first }         :true/false
            //{ $T.record$last }          :true/false
            //{ $T.record$total }     
            //{ $T.record$key }      
            //{ $T.record$typeof }     

            //{#break} {#continue}     、    ,       

        });
    </script>

    <style type="text/css">
        .jTemplatesTest {
            background: #DDD;
            border: 1px solid #000;
            margin: 2em;
            width: 480px;
        }

            .jTemplatesTest * {
                padding: 4px;
                margin: 2px auto;
            }

            .jTemplatesTest td, tr {
                background: #EEE;
                border: 1px solid black;
            }
    </style>
</head>

<body style="zoom: 1;">

    <!--         -->
    <textarea id="template" style="display: none">
<strong>{$T.name}: {$T.list_id}</strong>
<table>
{#foreach $T.table as record}
<tr>
<td>{$T.record$index+1}</td>
<td>{$T.record.id}</td>
<td>{$T.record.name}</td>
<td>{$T.record.age}</td>
<td>{$T.record.mail}</td>
</tr>
<tr>
<td colspan="5">Childs</td>
</tr>
{#foreach $T.record.childs as ch}
<tr>
<td></td>
<td></td>
<td></td>
<td>{$T.ch.name}</td>
<td>{$T.ch.age}</td>
</tr>
{#/for}
{#/for}
</table>
</textarea>
    <!--         -->

    <!--         -->
    <div id="result1" class="jTemplatesTest">
    </div>
    <!--         -->

    <!--JTemplate   :http://jtemplates.tpython.com/-->
</body>
</html>

좋은 웹페이지 즐겨찾기